簡體   English   中英

無法在我的.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?>

為什么是這樣? 我的代碼有什么問題? 請幫我。

提前致謝

夏魯

檢查php.ini

short_open_tag = 1;

並參見http://www.php.net/manual/zh/ini.core.php#ini.short-open-tag

第一次嘗試

 <?php echo $this->form ?>

如果可行,則您禁用了短標簽。 使用啟用它

short_open_tag = 1;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM