0
votes

hi I am new in zend framework Basically I want to populate company name list from the database. Actually I have doen it but i want to also populate its id in option box

example

select option value='1'> tcs option

select

this is my code

Application_Form_Clientcompanyform extends Zend_Form


$company_list = new Application_Model_Clientcompany; 
        $showlist  = $company_list->companyNameList();

        $list=array();
        $id=array();
                    foreach($showlist as $key => $value)
                         {
                             $list[]=$value['companyName']; 
                             $id[]=$value['id'];
                         }


$this->addElement('select', 'companyName', array(           

            'required'   => true,
            'filters'    => array('StringTrim'),
            'style'    => array('width:103px'),

            'multiOptions' => $list,
            'decorators'=>Array(
            'ViewHelper','Errors'

but Now i want to set the value in option in select box width $id from database

1

1 Answers

0
votes
$companyName = new Zend_Form_Element_Select('companyName');
$companyName->setRequired(true);
$companyName->addFilter('StringTrim');    
    $company_list = new Application_Model_Clientcompany; 
    $showlist  = $company_list->companyNameList();
    //add selections to multioption, assumes object...change notation if using array
    foreach($showlist as $company) {
        $name = ucfirst($company->name);
        $companyName->addMultiOption($company->id, $name);
    }
$this->addElement($companyName);

I know I changed the syntax style, I just find it easier to keep things straight this way.

Everything else you may need is in http://framework.zend.com/manual/1.12/en/zend.form.html, get used to using the reference and the the api for the framework, they really help.