Populating DB data to a Zend Form dropdown element
- zendnwar
- May 4, 2012
- Zend basic
- 11 Comments
$country_name = new Zend_Form_Element_Select('c_id', array( 'decorators' => $this->elementDecorators, 'label' => 'COUNTRY', 'attribs' => array('id' => 'c_id', 'class' => 'input-text-field'), 'required' => true, 'filters' => array('StringTrim') )); $c_table = new Application_Model_DbTable_Country(); foreach ($c_table->findForSelect() as $c) { $country_name->addMultiOption($c->c_id, $c->c_name); }
//Application/Model/DbTable/Country.php class Application_Model_DbTable_Country extends Zend_Db_Table_Abstract { protected $_name = 'country';//'country is a table name' public function findForSelect() { $select = $this->select(); return $this->fetchAll($select); } }
i hope it will be help for u. If u face any problem just reply me.