mercredi 16 septembre 2015

how can i display checkboxes from read data in database in view using form in zend 1.11

read form data from database and dispaly in checkbox in view using form in zend 1.11

  1. i create a roleController.php in zend controller

    public function init() { /* Initialize action controller here */ // do some thing } public function indexAction() { // action body // do some thing } } ?>

i also create role.php in form folder in zend 1.11

<?php

class Application_Form_Setting extends Zend_Form
{

    public function init()
    {
        /* Form Elements & Other Definitions Here ... */

        $this->setMethod('post');


        $this->addElement('checkbox', 'role[]', array(
            'filters'    => array('StringTrim')
        ));


        $this->addElement('button', 'Save', array(
            'value'    => 'Submit',
            'type'     => 'Submit',
            'class'    => 'btn blue'
        ));
        // Add the submit button


    $this->role[]->removeDecorator('Label');
        $this->role[]->removeDecorator('HtmlTag');
    $this->Save->removeDecorator('Label');
        $this->Save->removeDecorator('HtmlTag');
        $this->Save->removeDecorator('DtDdWrapper');
    }


}

?>

role.php in db-table folder in model

<?php

class Application_Model_DbTable_Role extends Zend_Db_Table_Abstract
{

    protected $_name = 'role_tbl';
    protected $_primary  = 'role_id';


}

in view role.phtml

<label><?php 
echo $this->form->getElement('role[]'); ?>Index</label>

my question is that how can i read data form database and display checkboxes in view using form

my role_table is

+-----------------------+------------------+
|   role_id             | role_name        | 
+-----------------------+------------------+
|      1                | Admin            |
|      2                | Manager          |
|      3                | Marketing Persion|
|      4                | Employee         |
+-----------------------+------------------+



Aucun commentaire:

Enregistrer un commentaire