Hello. My employer has decided to go for ZF2 after developing our own software platform from bottom the last 15 years. My task is to test it in the beta period and find out how to use the framework. I am new to ZF, but has a lot of experience from other frameworks and PHP systems.
At this point, I am testing different ways of using the MVC module system in our customer solutions. One of the issues there is how to make more dynamic layouts. I want to be able to use the same layouts but with different content based on different criteria. This might come from database (CMS settings etc), or it might be based on what happens in the controller.
So for instance, if I have this simplified layout view:
then a ViewModel class returned from the controller action could be the source of what is displayed in the "main" block. But then if i want to reuse this layout for many different pages, how can I best do that with a flexible way of including content in the "left" (and other similar) block? I have tried:
1. Putting a print($this->renderChildModel('left')); in the left block. I can then add a child model to the returned ViewModel in the controller, but then I have to add the child models in every controller action method.
2. If i run $this->render('something'); then another view (like a menu in the left block) can be rendered directly. This could work fine, but I might not always want to render the same content on different pages on the website.
If someone has a good example of how to do this, or can point me in the right direction, I would really appreciate it!
we had the same issue avoiding/reducing template changes from customers, so we've added placeholders like header, asideL, article, asideR, footer, etc
which are childmodels assigned to the layout. These placeholder models store their content in a stack/priority queue which will be iterated in their own templates. So you can just assign your content to one of the placeholder and let it automatically render to the selected place.