如何在Zend Framework + MySQL表中创建一个select - 选项
控制器:
$persons = new Application_Model_DbTable_Persons();
$data_persons = $persons->findPersons();
控制器和视图?如何? o.O
答案 0 :(得分:0)
在控制器
中 $this->view->dataPerson = $data_persons;
查看Html。
foreach($this->dataPerson as $datPers):
//Example Get person name.
echo $this->escape($datPers->name);
and etc.
endforeach;
答案 1 :(得分:0)
可以使用addMultiOptions()
函数
$persons = new Application_Model_DbTable_Persons();
$data_persons = $persons->findPersons();
$data_persons_array = array();
foreach($this->dataPerson as $datPers)
$data_persons_array[$datPers->id] = $datPers->name
$name = new Zend_Form_Element_Text('name');
$name->setLabel('name')
->setRequired(true)
->addValidator('NotEmpty');
->addMultiOptions($data_persons_array); //Will add the options to select box