如果我有:
// Controller
$this->Model->id = $id;
$this->request->data['Model'] = $this->Model->read();
进而:
// View (input field)
$this->Form->input('some_field'); // THE FORM FIELD WILL BE PRE-POPULATED
但是,如果我希望它成为一个选择框:
// View (with select)
$this->Form->select('some_field', $options); // THE SELECT BOX ISN'T PRE-POPULATED
那么问题:
一种。为什么选择框不像输入字段那样预先填充?
湾。我真的必须像这样手动预填充吗?
// View (with select)
$this->Form->select('some_field', $options, array('value' => $this->request->data['Model']['some_field'])); // THE SELECT BOX IS PRE-POPULATED
C。上述方法是预填充已经有值的选择框的最有效方法吗?