为什么Zend中的viewScript看不到表单?

时间:2013-01-08 21:13:12

标签: forms zend-framework2

你好我试图在viewscript中包含一个表单,但我不能这样做,我不知道为什么但是viewscript看不到我的表单.. 在控制器中我有这个:

namespace Application\Controller;

use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
use Zend\Authentication\AuthenticationService;
use MyAuth\Form\LoginForm;

class IndexController extends AbstractActionController
{

    public function indexAction()
    {   
        error_log("executing:".__METHOD__); 
        $this->view = new ViewModel();
        $form = new LoginForm();
        if(isset($this->view)){
            error_log("view exists in ".__METHOD__);
        }
        $this->view->form = $form;
    }
}

观点:

<div class="hero-unit">
    <h1><?php echo sprintf($this->translate('Welcome to %sZend Framework 2%s'), '<span class="zf-green">', '</span>') ?></h1>
    <p><?php echo sprintf($this->translate('Congratulations! You have successfully installed the %sZF2 Skeleton Application%s. You are currently running Zend Framework version %s. This skeleton can serve as a simple starting point for you to begin building your application on ZF2.'), '<a href="https://github.com/zendframework/ZendSkeletonApplication" target="_blank">', '</a>', \Zend\Version\Version::VERSION) ?></p>
    <p><a class="btn btn-success btn-large" href="https://github.com/zendframework/zf2" target="_blank"><?php echo $this->translate('Fork Zend Framework 2 on GitHub') ?> &raquo;</a></p>
</div>

<div class="row">
<?php
if(isset($this->form))
{
    error_log("form exists in ViewScript");
}else{
    error_log("form does not exists");
}
?>

    <div class="span4">
        <h2><?php echo $this->translate('Follow Development') ?></h2>
        <p><?php echo sprintf($this->translate('Zend Framework 2 is under active development. If you are interested in following the development of ZF2, there is a special ZF2 portal on the official Zend Framework website which provides links to the ZF2 %swiki%s, %sdev blog%s, %sissue tracker%s, and much more. This is a great resource for staying up to date with the latest developments!'), '<a href="http://framework.zend.com/wiki/display/ZFDEV2/Home">', '</a>', '<a href="http://framework.zend.com/zf2/blog">', '</a>', '<a href="http://framework.zend.com/issues/browse/ZF2">', '</a>') ?></p>
        <p><a class="btn btn-success" href="http://framework.zend.com/zf2" target="_blank"><?php echo $this->translate('ZF2 Development Portal') ?> &raquo;</a></p>
    </div>

发生了什么事?我已经2天试图解决它,但我无法解决它 感谢

2 个答案:

答案 0 :(得分:2)

您应该返回$ this-&gt;视图。我的建议:

$this->view->setVariable('form'=>$form);
return $this->view;

答案 1 :(得分:1)

Zend Framework 2与ZF1有很大不同。您不再需要分配名为$this->view的受保护变量。请参阅手册并阅读基础知识:

相关问题