how can i set data from database in check box using form in zend framework 1.11

爱⌒轻易说出口 提交于 2019-12-22 11:23:29

问题


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...



来源:https://stackoverflow.com/questions/32585977/how-can-i-set-data-from-database-in-check-box-using-form-in-zend-framework-1-11

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!