Note that there are some explanatory texts on larger screens.

plurals
  1. POZend Framework 2 display a view within a view
    text
    copied!<p>I have two modules Admin and Login.</p> <p>I want to display the Login view 'login.phtml' within the admin view 'index.html'</p> <p>I have the following in the Admin modules indexAction controller</p> <pre><code>public function indexAction() { $login = new LoginController(); $view = new ViewModel(array( 'theloginform' =&gt; $login-&gt;loginAction(), )); return $view; } </code></pre> <p>In the LoginAction method in the Login controller I return the ViewModel for the 'login.phtml' file.</p> <pre><code>public function LoginAction() { $view = new ViewModel(); return $view; } </code></pre> <p>The indexAction throws an error as the variable 'theloginform' is an object.</p> <pre><code>Catchable fatal error: Object of class Zend\View\Model\ViewModel could not be converted to string in... </code></pre> <p>If i add the following:</p> <pre><code>$authentication-&gt;loginAction()-&gt;captureTo('test') </code></pre> <p>The 'index.phtml' shows a string "content".</p> <p>I have read that i may need to render the ViewModel before i assign it to the view variable 'theloginform', but i can't seem to get it to work, i have tried the following with no luck.</p> <pre><code>public function LoginAction() { $view = new ViewModel(); $renderer = new PhpRenderer(); $resolver = new Resolver\AggregateResolver(); $map = new Resolver\TemplateMapResolver(array( 'login' =&gt; __DIR__ . '/../view/login.phtml' )); $resolver-&gt;attach($map); $view-&gt;setTemplate("login"); return $renderer-&gt;render($view); } </code></pre> <p>If get the following error:</p> <pre><code>Zend\View\Renderer\PhpRenderer::render: Unable to render template "login"; resolver could not resolve to a file </code></pre> <p>I have even tried adding the DI into the autoload_classmap.php file but still get the same error, i have double checked the login.phtml file is at the correct path:</p> <p>'/Login/view/login/login/login.phtml' I even copied it to '/Login/src/Login/view/login.phtml'</p> <p>Very confused have read then re-read the Zend documentation, i just want to pass a view to another view...</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