Is it a good practice to use database mappers in Zend View Helper? Because in my case this helper is making me a box of <div> that keeps changing in real time and is to be shown in all the views there are in my application. I can not possibly give that object loading it from the database in controllers and assign it to view everytime.
It would be really helpful if someone could tell good programming practices to follow when working with zend view helpers like:
- If it is OK to assign something to the view in the View Helpers by
$this->view->variable = ... ; - If it is OK to create and use models in View Helpers.
- If it is OK to use methods available to Zend_View inside a View Helper like by doing
$this->view->baseUrl('...');
Your second and third bullet points seem correct to me, as long as you don’t do any logical stuff in your model from your views. The link between models and views must be read-only.
Concerning your first point, you don’t need to assign anything to the view, you view helper should
returnyour HTML output directly to the view.About your first question, you could create View Helper that is specialized in this task, so you can use it as a simple proxy between your view helpers and mappers. One view helper will allow you to access to any mapper, and others view helpers can use this view helper to get a mapper.
Let’s see what Trygve Reenskaug thinks about MVC: