【问题标题】:how can i display checkboxes from read data in database in view using form in zend 1.11如何使用zend 1.11中的表单显示从数据库中读取数据的复选框
【发布时间】:2015-12-12 15:22:31
【问题描述】:

使用zend 1.11中的表单从数据库中读取表单数据并显示在复选框中

  1. 我在zend控制器中创建了一个roleController.php

    <?php
    
    class RoleController extends Zend_Controller_Action
    {
    
        public function init()
        {
            /* Initialize action controller here */
        // do some thing    
    
        }
        public function indexAction()
        {
            // action body
        // do some thing    
        }               
    }            
    ?>
    

我还在 zend 1.11 的表单文件夹中创建了 role.php

<?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');
    }


}

?>

模型中 db-table 文件夹中的role.php

<?php

class Application_Model_DbTable_Role extends Zend_Db_Table_Abstract
{

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


}

查看 role.phtml

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

我的问题是如何读取数据表单数据库并使用表单在视图中显示复选框

我的角色表是

+------------------------+------------------+ |角色 ID |角色名 | +------------------------+------------------+ | 1 |管理员 | | 2 |经理 | | 3 |营销观点| | 4 |员工 | +------------------------+------------------+

【问题讨论】:

标签: php forms zend-framework checkbox zend-form


【解决方案1】:

检查以下代码。

class YourForm extends Zend_Form
{
    public function init()
    {

       $DBCnt = getCountofRowsFromDB();

       for($i = 0; $i <= $DBCnt; $i++){
           $checkBoxes[] = new Zend_Form_Element_Checkbox('checkBox_' . $i);//THIS IS WHERE YOU CREATE AND SET THE CHECKBOXES
       }
       $this->addElements($checkBoxes); //THIS IS WHERE YOU ADD THE CHECKBOXES TO THE FORM
  }
}

【讨论】:

  • 我以 zend 形式声明代码。它是定义错误......我问你你以zend形式声明的代码。
  • 我的问题是,如何使用从 role_master 数据库读取数据的表单声明一个复选框列表。意味着开发人员在名为 checkbox 的表单中声明一个复选框的添加元素然后读取值表单 Role master 然后显示在视图中,就像我在我的问题部分中设置图像一样,当我提交时,我想要我选择的复选框的值.....再看我的问题..上面你可以很容易理解..现在我的问题给你你在你身边声明的代码是什么......
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-10-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多