user554940
user554940

Reputation:

Why viewScript in Zend can't see the form?

Hello I am trying to include a form in the viewscript but I can't do it, I don't know why but the viewscript does not see my form.. In the controller I have this:

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;
    }
}

And the 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>

What is happening? I've been 2 days trying to solve it but I could not solve it Thanks

Upvotes: 0

Views: 205

Answers (2)

Sam
Sam

Reputation: 16455

Zend Framework 2 works significantly different than ZF1. You no longer need to assign a protected variable called $this->view. Please refer to the manual and read yourself into the basics:

Upvotes: 1

samsonasik
samsonasik

Reputation: 540

You should return $this->view. my suggestion :

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

Upvotes: 2

Related Questions