Kohana 3将返回的对象转换为选择选项


kohana 3 convert returned object into select options

很难弄清楚如何接受返回的FORM对象并将其转换为辅助FORM::select的可用数组

$this->template->content = View::factory('form')
->bind('errors', $errors)
->bind('categories', $categories);

$categories = ORM::factory('category');
$categories->order_by('category');
$categories = $categories->find_all();

在表单视图中我有

<tr>
<td><?php echo Form::label('category', 'Category'); ?></td>
<td><?php echo Form::select('category', $categories, $category); ?></td>
</tr>

如何将返回的对象数组$categories转换为属性数组$categories

as_array()可以帮您完成这个任务。就用这一行。

$categories = $categories->find_all()->as_array('id', 'category_label');