表单元素未显示?
在 projectfolder/application/forms/Login.php 中创建表单
class Form_Login extends Zend_Form {
public function _construct() {
$this->setMethod('post');
$elements = array();
$element = $this->addElement('text', 'username');
$element->setLabel('Username');
$elements[] = $element;
$element = $this->addElement('password', 'password');
$element->setLabel('Password');
$elements[] = $element;
$this->addElements( $elements );
$this->setElementDecorators( array( 'ViewHelper' ) );
}
}
myproject/application/controllers/AuthenticationController.php 中的表单
public function loginAction() {
$this->view->heading = 'Login';
$this->view->form = new Form_Login();
}
访问login.phtml 中
<h1><?= $this->heading; ?></h1>
<?= $this->form; ?>
< strong>问题:
显示标题,但未显示任何表单元素。我在这里做错了什么?
谢谢
Created Form in projectfolder/application/forms/Login.php
class Form_Login extends Zend_Form {
public function _construct() {
$this->setMethod('post');
$elements = array();
$element = $this->addElement('text', 'username');
$element->setLabel('Username');
$elements[] = $element;
$element = $this->addElement('password', 'password');
$element->setLabel('Password');
$elements[] = $element;
$this->addElements( $elements );
$this->setElementDecorators( array( 'ViewHelper' ) );
}
}
Accessing Form in myproject/application/controllers/AuthenticationController.php
public function loginAction() {
$this->view->heading = 'Login';
$this->view->form = new Form_Login();
}
in login.phtml
<h1><?= $this->heading; ?></h1>
<?= $this->form; ?>
Problem:
Heading is shown but not any form element is shown. What am I doing wrong here ?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
它是
__construct()
,而不是_construct()
。It's
__construct()
, not_construct()
.这是我的完整解决方案:
Login.php中的表单类:
login-form.phtml
Here is my complete solution:
Form Class in Login.php:
login-form.phtml