开发者

dropdown select in cakePHP

I am using CakePHP 1.2. I have a person model that hasMany 'Docume开发者_JAVA百科nt'. When I edit a document, the select box for the owning person appears (echo $form->input('person') where person has been defined in the documents_controller like this:

$allPeople = $this->Document->Person->find('list', array('fields' => array('first_name')));
$this->set('people', $allPeople);

When I edit a document's record, I want the person owning the document to be selected and displayed in the box. Right now, the app just makes the list box but doesn't highlight the correct owner (though the DB has the person's id).

Thank you, Frank Luke


In your edit view, you should add an extra parameter to your $form->select(), called $selected. This way, you can specify which item should be selected from the list.

Example (just an example, you should rewrite it for your own situation):

<?php echo $form->select('Document.person', $allPeople, $this->data['Document']['Person']['id']); ?>

More information:
http://book.cakephp.org/view/728/select

-- Bjorn

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜