Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Taken from <a href="http://www.michaelgallego.fr/blog/2012/10/06/how-to-replace-the-action-helper-in-zf-2-and-make-great-widgetized-content/" rel="nofollow">this blog</a>, which explains in depth why $this->view->action() has been removed from ZF2, an example how to use the forward() (<a href="https://packages.zendframework.com/docs/latest/manual/en/modules/zend.mvc.plugins.html#forward-plugin" rel="nofollow">ZF2 documentation</a>) controller plugin:</p> <p>You can forward all necessary data to another controller inside your index controller action using the forward() controller plugin like this:</p> <pre><code>public function indexAction() { $view = new ViewModel(); $login_param = $this-&gt;params('login_param'); $login = $this-&gt;forward()-&gt;dispatch('App\Controller\LoginController', array( 'action' =&gt; 'display', 'login_param' =&gt; $login_param )); $view-&gt;addChild($login, 'login'); return $view; } </code></pre> <p>In your view, all you need to do is:</p> <pre><code>&lt;?php echo $this-&gt;login; ?&gt; </code></pre> <hr> <p>Please note that the forward() plugin might return a <code>Zend\Http\PhpEnvironment\Response</code> instead. This happens if you use a redirect() in your login controller / action.</p> <hr> <p>Also, if the Servicemanager claims to not find <code>App\Controller\LoginController</code>, have a look in your module.config.php. Look for a section called <code>controllers</code>.<br> Example:</p> <pre><code>[...] 'controllers' =&gt; array( 'invokables' =&gt; array( 'LoginCon' =&gt; 'App\Controller\LoginController', 'IndexCon' =&gt; 'App\Controller\IndexController', 'DataCon' =&gt; 'App\Controller\DataController', ) ), [...] </code></pre> <p>Here, there is an alias for your login controller called <code>LoginCon</code>, you should use this name as controller name in the dispatch() method instead.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload