With Zend_Layout on the horizon, I've been looking at how to use it and it will remove the need for my own front controller plugin which I call SiteTemplate. As a result, I need to find a new home for the view customisation stuff I do in SiteTemplate.
My current plan is to create a new front controller plugin called ViewSetup (for want of a better name!) that contains just the view setup stuff from
* Front Controller plug in to set up the view with the Akra view helper
* path and some useful request variables.
class Akra_Controller_Plugin_ViewSetup extends Zend_Controller_Plugin_Abstract
public function dispatchLoopStartup(Zend_Controller_Request_Abstract $request)
$viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
// add helper path to View/Helper directory within this library
$prefix = 'Akra_View_Helper';
$dir = dirname(__FILE__) . '/../../View/Helper';
// set up variables that the view may want to know
$viewRenderer->view->baseUrl = $request->getBaseUrl();
$viewRenderer->view->module = $request->getModuleName();
$viewRenderer->view->controller = $request->getControllerName();
$viewRenderer->view->action = $request->getActionName();
$viewRenderer->view->theme = $request->getParam('theme', 'default');
(I'll talk about how cool Akra_View is another time...)
I had a dig into Zend_Layout's source and it collects its view object from the view renderer too, so this works as expected. (*phew*!)
The alternative, as I see it is to put the view creation into my bootstrap and then create a series of view helpers like this one for the base url:
$fc = Zend_Controller_Front::getInstance();
$request = $fc->getRequest();
$this->_baseUrl = $request->getBaseUrl();
How does everyone else do it? Is the bootstrap + many view helpers approach a better one than using a front controller plugin? Have I missed a completely obvious better solution?