ViewModel setTerminal not working properly

Hey Guys, i got a strange issue which i am not sure why it does occur.

So basicly i got this code in my controller:

$view = new ViewModel();
$view->setTemplate('myportal/box/boxtype');
return $view;

Everything gets displayed correctly, but once i set

$view->setTerminal(true);

to not display the layout, it instead does not display the view.

Someone had this issue before?

Everything works like expected. Activate the error output, maybe there are other problems.

Everything works like expected.
I dont think so, in my ZF2 Version the

$view->setTerminal(true) 

works like expected. I got this project in ZF2 and Laminas side by side. The same code but the
behaviour is different. In Zf2 setTerminal, does not allow the layout to be rendered, only the site content will be returned.

In laminas however, the behaviour is exactly the opposite. the site-content does not get displayed, only the layout.

i dont get any exceptions thrown nor do i get any errors :confused:

So i just tested it with getting the PhpRenderer in the Controller and echo the generated ViewModel (from above) and everything displayes correctly. So i think the problem might be in a configuration flag? or something like that?

the view manager setting in my module.config.php are like that:

'view_manager' => array(
		'display_not_found_reason' => true,
		'display_exceptions' => true,
		'exception_template' => 'error/index',
		'template_path_stack' => array(
			__DIR__ . '/../view',
		),
		'template_map' => array(
			'layout/admin' => __DIR__ . '/../view/layout/layout.phtml',
		)
	)

There are no changes from zend-mvc or zend-view to laminas-mvc and laminas-view on this topic.

Nothing wrong here.


And yes, I have tested this myself:

  1. Install MVC Skeleton Application
    composer create-project -sdev laminas/laminas-mvc-skeleton my-application
    
  2. Update Controller Action
    namespace Application\Controller;
    
    use Laminas\Mvc\Controller\AbstractActionController;
    use Laminas\View\Model\ViewModel;
    
    class IndexController extends AbstractActionController
    {
        public function indexAction()
        {
            return (new ViewModel())->setTerminal(true);
        }
    }
    

Output

<div class="jumbotron">
    <h1 class="display-4">Welcome to<br>Laminas MVC Skeleton Application</h1>

    <p>
        Congratulations! You have successfully installed the
        <a href="https://github.com/laminas/laminas-mvc-skeleton" target="_blank">Laminas MVC Skeleton</a>.
        This skeleton can serve as a simple starting point for you to begin
        building your application on Laminas MVC.
    </p>

    <hr class="my-4">

    <a class="btn btn-primary btn-lg" href="https://github.com/laminas" target="_blank">Check Laminas on GitHub &raquo;</a>
</div>

<div class="card-deck">
    <div class="card">
        <h2 class="card-header">Follow Development</h2>
        <div class="card-body">
            <p>
                Laminas Project is under active development. If you are
                interested in following the development, you can check
                <a href="https://getlaminas.org/blog/">Laminas dev blog</a>,
                and <a href="https://github.com/issues?utf8=%E2%9C%93&amp;q=is:issue+org:laminas">Laminas issue tracker</a>
                (link requires a GitHub account). This is a great resource
                for staying up to date with the latest developments!
            </p>

            <a class="btn btn-primary" href="https://getlaminas.org/" target="_blank">Laminas Project Portal &raquo;</a>
        </div>
    </div>

    <div class="card">
        <h2 class="card-header">Discover Modules</h2>
        <div class="card-body">
            <p>
                Laminas MVC is a modular application.
                You can find multiple compatible modules on packagist.
            </p>

            <a class="btn btn-primary" href="https://packagist.org/?tags=module~zf2~zendframework~zend%20framework~zend%20framework%202~zf3~zf~zend~laminas" target="_blank">Explore Laminas Modules &raquo;</a>
        </div>
    </div>

    <div class="card">
        <h2 class="card-header">Help &amp; Support</h2>
        <div class="card-body">
            <p>
                If you need any help or support while developing with Laminas,
                you may reach us via <a href="https://laminas.dev/chat">chat</a> or
                <a href="https://discourse.laminas.dev">forum</a>.
                We'd love to hear any questions or feedback you may have
                regarding any release.
            </p>

            <a class="btn btn-primary" href="https://laminas.dev/chat" target="_blank">Ping us on chat &raquo;</a>
        </div>
    </div>
</div>

Are there any listeners or something else in your application which can change or switch the layout?

Thank you very much @froschdesign, for pushing me into the right direction.

The Problem was, that the LayoutListener https://docs.laminas.dev/laminas-view/cookbook/setting-module-specific-layouts/ always set the setTemplate even if you told the ViewModel with setTerminate to not display the template.

A Pull-Request has been made and this problem should not occur in the future. https://github.com/laminas/laminas-view/pull/54

Greetings
mhaendler

1 Like