I’m trying to limit 1 option in the dropdown menu by calling Zend_Auth to get the username of the user logged in. The code seems fine, but it only displays 1 blank space in the dropdown menu.
$auth= Zend_Auth::getInstance();
$user= $auth->getIdentity();
$username = $user->username;
$memberid = $this->createElement('select', 'memberid'); //dropdown menu of member name
$memberid->setLabel('Member Id')
->setRequired(true);
$db_member = new Application_Model_DbTable_Register();
$select = $db_member->select('userid')
->from(array('usertable'))
->where('usertable.username = ?', $username);
$row = $db_member->fetchRow($select);
$memberid->addMultiOption($row['userid']);
Method
addMultiOptiontakes two parameters: $option and $value, so instead oftry to make something like
Where
user_idis a name of the option element.Also I advise you to make separate forms and models and not to write DB and forms code in controllers
And also, why are you making the query to database to retrieve the user_id? You can get user_id just form
authobject.