I have a form with a select element that I need to populate with values ββfrom the database. In particular, the name and identifier of current users. Function fetchPairs()works great for this! However, I need to combine the value from the column first_nameand column last_nameand display it as a parameter label. Is there any way to do this and still use fetchPairs()? If not, how can I achieve the same result? Here is an excerpt from the code that is currently working:
<?php
class Default_Form_AddUser extends Zend_Form
{
public function init()
{
$this->addElement('select', 'user', array(
'label' => 'Select user:',
'required' => true,
'multiOptions' => $this->_getSelectOptions()
));
}
protected function _getSelectOptions()
{
$db = Zend_Db_Table::getDefaultAdapter();
$select = $db->select()->from('users', array('id', 'first_name'));
$roleOptions = $db->fetchPairs($select);
return $roleOptions;
}
}
source
share