可以';t在我的.phtml文件中显示Zend表单


Can't display a Zend Form in my .phtml file

我正在使用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

检查php.ini中的

short_open_tag = 1;

看看http://www.php.net/manual/en/ini.core.php#ini.short-打开标签

首次尝试

 <?php echo $this->form ?>

如果这有效,那么您禁用了短标记。使用启用

short_open_tag = 1;