0
votes

I am new to zend framework. I want to call option values in select box dynamically in view file without using zend form. Please help

MY OLD CODE

$txtCategory = new Zend_Form_Element_Select('category');        
$txtCategory->setLabel('Category')
        ->setRequired(true);
$table = new Application_Model_DbTable_Category();

foreach ($table->getcategory() as $c) {
        $txtCategory->addMultiOption($c->ExpenseCategoryID, $c->Category);
}

My categories are in select box.

2
On SO, it's best to provide the code that you are working with. What have you tried so far?yumaikas
before this i have called options values dynamically using zend form. But now i want to do it without using zend form. So, I don't know how to do thisnav
Could you put the code that you don't want to use into your question?yumaikas
i have paste my old codenav

2 Answers

0
votes

You can simply echo the element on your view if you don't want to use zend_form

In controller

$table = new Application_Model_DbTable_Category();
$this->view->categories = $table->getcategory();
$this->view->selected = "X"; // currently selected value

In view

<form>
  <select name="select2" size="3" multiple="multiple" tabindex="1">
     <?php $selected = $this->selected;
     foreach($this->categories as $c) {
       echo "<option value=\"" . $c->ExpenseCategoryID . "\"" . ($c->ExpenseCategoryID ==   $selected ? " selected=\"selected\">" : ">") . $c->Category . "</option>";
     }?>
    </select>
  //rest of the element
</form>
0
votes

You're going to need to learn how to use AJAX and javascript to talk to your PHP server. It's going to be a bit harder than using the Zend form like you are now. Some links with tutorials:

Tutorialspoint on PHP and AJAX

Tutorials point AJAX series