how can i set data from database in check box usin

2019-05-23 10:18发布

问题:

I have a one table name is task_master. I want to set all record into check box dynamically in zend. I see so many examples but i didn't found anything to fix it.

Task master

id  name<br>
1   Index<br>
2   Add<br>
3   Edit<br>
4   delete<br>

i have new in zend. have any suggestion about it. how can i set data from database in check box using form in zend.

like following.

read from database and create list of check box in view.

回答1:

I am not able to make out much from the code that you have shared but this might be able to help you.

IN YOUR FORM:

class YourForm extends Zend_Form
{
    public function init()
    {

       $taskMasterCnt = getCountofRowsFromTaskMaster();

       for($i = 0; $i <= $taskMasterCnt; $i++){
           $checkBoxes[] = new Zend_Form_Element_Checkbox('checkBox_' . $i);
       }
       $this->addElements($checkBoxes);
  }
}

IN YOUR HTML:

<div class="checkbox">
   <?= $this->form->getElement('checkBox_0') ?> <span>Index</span>
</div>
<div class="checkbox">
   <?= $this->form->getElement('checkBox_1') ?> <span>Add</span>
</div>

and so on...