我最近正在使用zend。我发现了这个 ViewScript 表单装饰器,我发现它是使用经典 Zend 表单装饰器的最佳选择。但我在显示表格时遇到问题。我得到了代码,但没有从视图中得到显示。
这是我的代码:
形式:
class Application_Form_Registration extends Zend_Form
{
public function init()
{
$username = new Zend_Form_Element_Text("username");
$submit = new Zend_Form_Element_Submit("submit");
$this->setAction("/test.php");
$this->setMethod("get");
$this->addElements(array($username, $submit));
$this->setElementDecorators(array(
array('ViewScript', array(
'viewScript'=>'test.phtml'
))
));
}
}
控制器:
class IndexController extends Zend_Controller_Action
{
public function init()
{
}
public function indexAction()
{
$form = new Application_Form_Registration();
$this->view->form = $form;
}
}
test.phtml(我的 ViewScript)
<form action="<?php $this->escape($this->form->getAction()); ?>">
<div style="width: 100px; height: 100px; background: blue;">
<?php echo $this->element->username; ?>
<?php echo $this->element->submit; ?>
</div>
</form>
我的观点(index.phtml)
<?php echo $this->form; ?>
我错过了什么和/或上面的代码出错了吗?