我嘗試做這種方式:的Zend - 填充組合框與數據庫返回的數據
public function init()
{
/* Form Elements & Other Definitions Here ... */
$sets_table = new Optionals_Model_DbTable_Sets();
$set = new Zend_Form_Element_Select('set');
$set ->setLabel('Alegeti setul de optionale:');
foreach ($sets_table->getSets() as $value) {
echo $value->cod_set_optional;
$set->addMultiOption($value->cod_set_optional);
}
$submit = new Zend_Form_Element_Submit('Continua');
$this->addElements (array (
$set,
$submit
));
}
,其中來自DBTABLE getSets()看起來是這樣的:
public function getSets()
{
$select = $this->select();
$rows = $this->fetchAll($select);
if (!$rows) {
throw new Exception("Could not find!");
}
return $rows;
}
我見過這種做它HERE,但它不起作用。回聲工作正常,但組合框未填充。我的代碼有什麼問題嗎?
謝謝! 索林
但我只想給ID添加到combobox – 2012-04-13 12:04:15
我這樣做** $ set-> addMultiOption($ value-> cod_set_optional,$ value-> cod_set_optional); ** be因爲我只需要代碼...謝謝 – 2012-04-13 12:06:53