Favourite Kohana Tips & Features?

The Pixel Developer picture The Pixel Developer · Mar 6, 2010 · Viewed 8.6k times · Source

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

  • Please, include only one tip per answer.
  • Add Kohana versions if necessary.

This is a community wiki.

Answer

Kemo picture Kemo · Aug 1, 2010

Generating Form::select() options from database result

Kohana 3.1 and 3.0

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

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

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.

If you want to add a default option:

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