最喜欢的Kohana秘诀与技巧特征? [英] Favourite Kohana Tips & Features?

查看:56
本文介绍了最喜欢的Kohana秘诀与技巧特征?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

受其他社区Wiki的启发,我有兴趣了解鲜为人知的Kohana技巧,窍门和功能.

Inspired from the other community wikis, I'm interested in hearing about the lesser known Kohana tips, tricks and features.

  • 请,每个答案只包含一个提示.
  • 如有必要,添加Kohana版本.

这是社区Wiki .

推荐答案

从数据库结果中生成Form :: select()选项

Kohana 3.1和3.0

$options = ORM::factory('model')
 ->order_by('title','ASC')
 ->find_all()
 ->as_array('id','title');

$select = Form::select('name', $options);

应该注意,这不限于ORM,并且可以用于所有数据库结果(它们都支持as_array).有关更多详细信息,请参见数据库结果信息.

It should be noted this is not restricted to the ORM and can be used on all database results (they all support as_array). See the database results information for more details.

如果要添加默认选项:

$options = Arr::merge(array('Please select a value.'), $options);

这篇关于最喜欢的Kohana秘诀与技巧特征?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆