I'm learning Zend Framework 2 and walked already through the famous Album tutorial. So I've a basic understanding what’s going on but unfortunately I miss a fundamental part about layouts.
I want to build a basic Web application that supposed to have:
I've installed the ZF2 Skeleton Application and the Zfcuser module. The site and registration pages show up like they supposed to.
I'll find all layout files in Application/view and the configured path in Application/config/module.config.php
But I have still a couple of questions:
How can I load a different layout according a user is logged in or not? The zfcUser module provides an helper for that:
if(!$this->zfcUserIdentity()):
But I don't know where to add it.
Thank you so much in advance. And if anyone has a good link to a tutorial - please post it. I really appreciate it.
<html>
<body>
<?php
// render template from view/partials/header.phtml
echo $this->partial('partials/header');
?>
<?php echo $this->content; ?>
<?php
// render template from view/partials/footer.phtml with some additional variables from layout scope
echo $this->partial('partials/footer', [
'variable' => 'value',
]);
?>
</body>
</html>
// module.config.php
'view_manager' => [
'template_map' => [
'zfc-user/user/login' => '/path/to/custom/login-template',
],
],
if($this->zfcUserIdentity()) {
$this->layout('layout/members');
}
Definitely take a look at this (incomplete) ZF2 Quick Start rewrite with some best practices.