2009年6月29日星期一

[fw-mvc] Form - Add a method to populate a select .

Hi. To populate a select I ended up with this code
 class Form_User extends Zend_Form {     protected $_roleData;          public function init()     {                   $this->setMethod('post');         $this->setAttribs(array('id'=>'frm-user','class'=>'large center'));                  // Roles           $this->addElement('select', 'role_id', array(            'multiOptions' => $this->_roleData,             'value' => '0',             'required'   => true,             'validators' => array(                 'Digits'             )         ));              }          public function setRoleData($data){                   $this->_roleData = $data;     } } 
in the controller
 protected function _getform(array $data = null)     {         return $this->getHelper('FormLoader')->load('user',array(             'action' => $this->_helper->url('add'),'RoleData' => $data));            } 
I'm wondering if there is something built-in in zf (I know populate but I'm not able to apply it at this case) or an other way to populate a select. I'd like to avoid to put a model in the form. Bye.

View this message in context: Form - Add a method to populate a select .
Sent from the Zend MVC mailing list archive at Nabble.com.

没有评论: