我分配了
$this->view->form = $form
(表单实例),现在尝试使用在layout.phtml中显示内容
echo $this->form;
但没有显示任何东西。我尝试使用检查内容
print_r($this);
我看到没有数据加载到[log:Zend_View_Abstract:private]
。
谁能帮助我如何在phtml文件中加载数据。
AuthForm.php
class forms_AuthForm extends Zend_Form
{
public function __construct($options = null)
{
parent::__construct($options);
$this->setName('login');
$username = new Zend_Form_Element_Text('username','username');
$username->setLabel('Username:')
->setRequired(true)
->setOptions(array('class'=>'longfield'));
$password = new Zend_Form_Element_Text('password','password');
$password->setLabel('Password: *')
->setRequired(true);
$submit = new Zend_Form_Element_Submit('submit','submit');
$submit->setLabel('Login');
$this->addElements(array($username, $password,$submit));
}
}
和AuthController.php
$form = new forms_AuthForm();
$this->view->form = $form;
Regrds 基兰
答案 0 :(得分:0)
我不确定,但我认为您必须将表单分配给布局而不是视图。
$layout = Zend_Layout::getMvcInstance();
$form = new forms_AuthForm();
$layout->form = $form;
并在 layout.phtml
中echo $this->layout()->form;