【发布时间】:2015-12-12 15:22:31
【问题描述】:
使用zend 1.11中的表单从数据库中读取表单数据并显示在复选框中
-
我在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 |员工 | +------------------------+------------------+【问题讨论】:
-
试试我在以下链接中提到的解决方案。 stackoverflow.com/questions/32585977/…
-
但是如何在表单中设置复选框
标签: php forms zend-framework checkbox zend-form