I have a form with a select element that I need to populate with values from a database. Specifically, the name and id of the current users. The fetchPairs()
function works great for this! However, I need to concatenate the value from the first_name
column and the last_name
column and display this as the option label. Is there a way to do it and still use fetchPairs()
? If not, how can I achieve the same result? Here's an excerpt of the code that is currently working:
<?php // excerpt
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;
}
}