Я работаю с Zend совсем недавно. Я обнаружил этот декоратор ViewScript для формы и считаю его лучшей альтернативой использования
классический Zend Form Decorators. Но у меня проблема с отображением формы. Я получил работающий код, но не получил отображение из вида.
Вот мои коды:
Форма:
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 (My 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; ?>
Я что-то пропустил и / или сделал неправильно с вышеуказанным кодом?