Reputation: 6246
I'm looking to migrate some of my projects from our custom framework into ZF2. In our framework we have one 'global' controller what sets up the page layout, header, gets any data from the database that's needed on every page, and then all other controllers for separate pages extend of of that.
What's the 'Zend' way of doing this? E.g. on every page I need to run a query SELECT html FROM dbcms.adverts
and display the html
field on every page.
Upvotes: 1
Views: 73
Reputation: 16445
You would create a ViewHelper
that gains access to the Database. This access is done by having any DB-Access-Tool you want (TableGateway
, Doctrine2
, DbAdapter
, etc..) and pass this into the ViewHelper
.
The ViewHelper
then would simply return the HTML-String. And inside your Layout and/or View-Scripts you'd use the ViewHelper
in the likes of echo $this->myHtmlViewHelper()
.
Upvotes: 2