在CakePHP中使用FormHelper创建“选择”列表框 [英] Creating 'select' listboxes using FormHelper in CakePHP
本文介绍了在CakePHP中使用FormHelper创建“选择”列表框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个模型, Category
和 Point
。关联定义为:
I have two models, Category
and Point
. The associations are defined as:
Category hasMany Point
Point belongsTo Category
我想在将 Points
添加到我的数据库时,它属于< select>
框,以及表单数据的其余部分。
I would like, when adding Points
to my database, to be able to select the category it belongs to from a <select>
box, along with the rest of the form data.
我需要设置
类别列表,我该如何做呢?
Where would I need to set
the category list and how could I do it? And how would I produce the select box?
我假设可以用
$form->input('categorieslist',array('type'=>'select')); //categorieslist needs
//setting somewhere.
推荐答案
在控制器中:
$categories = $this->Point->Category->find('list');
$this->set(compact('categories'));
在视图中:
$form->input('category_id',array('type'=>'select'));
这篇关于在CakePHP中使用FormHelper创建“选择”列表框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文