无法在.phtml文件中显示Zend表单

时间:2012-07-10 09:51:09

标签: php zend-framework zend-form

我正在使用Zend Framework开发一个小型php应用程序。我使用Zend_Form创建了一个表单,但是当我尝试在浏览器中显示它时,它无法正常工作。

这是我的Form类:     

class IndexForm extends Zend_Form {

public function init(){

    $this->setAction('main/main');
    $this->setMethod('post');
    $username = $this->addElement('text','uname',array('filters'=>array('StringTrim','StringToLower'),
             'validators'=>array('Alpha',
                array('StringLength',false,array(3,20)),
            ),
            'required'=>true,
            'label'=>'User Name:'));

    $password = $this->addElement('password','pwd',array('filters'=>array('StringTrim'),
            'validtors'=>array('Alnum',
            array('StringLength',false,array(6,20)),),
            'required'=>true,
            'label'=>'Password:'
            ));

    $login = $this->addElement('submit', 'login', array(
            'required' => false,
            'ignore'   => true,
            'label'    => 'Login',
    )); 
    }
}

?> 

这是我的IndexController.php

<?php

class IndexController extends Zend_Controller_Action {

public function init() {
    /*
     * Initialize action controller here
     */
}

public function indexAction() {
    include APPLICATION_PATH.'/models/Forms/IndexForm.php';
    $form = new IndexForm();
    $this->view->form = $form;
}

}

这是我的index.phtml,我需要在其中显示表单。

<html>
<style>
</style>

<body><br>
<img alt="" src="http://localhost/Accounts/application/views/scripts/images/logo.png" width=200px height=80px><!-- see whether you can get the host name dynamically -->
<div id="text" >
<h1>Welcome</h1><br><hr>
<h4>Please Log in To View The Main Page</h4></div>

<?=$this->form?> <!--here I want to display the form-->

<div><?php include APPLICATION_PATH.'/views/scripts/layouts/footer.php';?>
</div>
</body>
</html>

我得到的输出而不是表单是form?>

这是为什么?我的代码有什么问题?请帮帮我。

提前致谢

Charu

2 个答案:

答案 0 :(得分:1)

检查php.ini是否

short_open_tag = 1;

请参阅http://www.php.net/manual/en/ini.core.php#ini.short-open-tag

答案 1 :(得分:0)

首先尝试

 <?php echo $this->form ?>

如果此方法有效,则禁用短标签。使用

启用它
short_open_tag = 1;