0

こんにちは私は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;
    }
}

そしてviewscript:

<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日が経ちましたが、私はそれを解決することができませんでしたありがとう

4

2 に答える 2

2

$this->view を返す必要があります。私のおすすめ :

$this->view->setVariable('form'=>$form);
return $this->view;
于 2013-01-08T22:58:41.427 に答える
1

Zend Framework 2 は、ZF1 とは大きく異なる動作をします。という名前の保護変数を割り当てる必要はなくなりました$this->view。マニュアルを参照して、基本を読んでください。

于 2013-01-09T06:24:40.810 に答える