Search code examples
phpheaderzend-framework2footer

How to use views / layouts in different modules


i am new to Zend Framework 2 and try to set up my first project. I set up the skelleton Application and now i try to create a "header" and "footer" that can be used in every module.

As a header and footer i mean normal html text that includes links to imprint etc.

I thought of creating a new module ( basic module ) which includes the header and footer and then make this module available in all other modules so the other modules will all use the same header and footer.

Is this the right way ?

If yes : 1. Do i define the html things in the "module/view/layout" folder ? 2. How to define that the other modules will include the basic module ? 3. Is there a tutorial for this or what are the right words for that i am looking for, so i can use google even better.

If no : 1. What is the right way to achieve that ?

Thanks :).


Solution

  • In ZF2 the configuration is generated merging all config files. The last module registered in 'application.config.php' will override any previous value.

    So if you want to share the same layout in all of your modules, you can define it in your Application module. Then remove the other modules configuration related to the layout like the 'layout/layout' key in the 'template_map' section of the 'view_manager, in your 'module.config.php'.

    I recommend you to follow the official docs where this is well explained.