本文介绍了表单元素未显示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

projectfolder / application / forms / Login.php中创建了表单

 类Form_Login扩展了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'));


$ b

访问 myproject中的表单/application/controllers/AuthenticationController.php

  public function loginAction(){
$ this-> ; view-> heading ='Login';
$ this-> view-> form = new Form_Login();
}

位于 login.phtml

 < h1><?= $ this->标题; ?>< / H1> 
<?= $ this->表单; ?>

问题:

显示标题,但没有显示任何表单元素。我在这里做错了什么?



感谢

解决方案

code> __ construct(),而不是 _construct()


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

解决方案

It's __construct(), not _construct().

这篇关于表单元素未显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 22:13