简体   繁体   中英

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

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.

在此处输入图片说明

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM