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
精彩评论