Fra*_*uke 2 select cakephp associations cakephp-1.2 drop-down-menu
我正在使用CakePHP 1.2.我有一个人模型,有很多'文件'.当我编辑文档时,会出现所属人员的选择框(echo $form->input('person')其中person已在documents_controller中定义,如下所示:
$allPeople = $this->Document->Person->find('list', array('fields' => array('first_name')));
$this->set('people', $allPeople);
Run Code Online (Sandbox Code Playgroud)
当我编辑文档的记录时,我希望拥有该文档的人被选中并显示在框中.现在,应用程序只是创建列表框但没有突出显示正确的所有者(尽管数据库具有该人的ID).
谢谢Frank Luke
在编辑视图中,您应该在$ form-> select()中添加一个额外的参数,名为$ selected.这样,您可以指定应从列表中选择哪个项目.
示例(只是一个示例,您应该根据自己的情况重写它):
<?php echo $form->select('Document.person', $allPeople, $this->data['Document']['Person']['id']); ?>
Run Code Online (Sandbox Code Playgroud)
更多信息:http:
//book.cakephp.org/view/728/select
- 比约恩