how to get selectbox value name in action of zend controller
I have a select box in a zend form which is filled from database
$topics = Doctrine_Core::getTable('Model_Topic')->findAll();
$topic = new Zend_Form_Element_Select('topic');
$topic->setLabel('Topic')->setRequir开发者_如何学编程ed(true);
foreach($topics as $topics1) {
$topic->addMultiOption($topics1->id, $topics1->title);
}
in action I can get the value like $topic =$form->getValue('topic');
this will give me the ID but how can I get the name of that ID?
You can fetch the option "value" (as in the text value) by getting the entire set of multi-options and picking the selected one by the array key
$topic = $form->getValue('topic');
$options = $form->topic->getMultiOptions();
$topicTitle = $options[$topic];
精彩评论