Hi Ninja,
You need to do two things:
1. Configure a custom Zend_View instance for your common paths (only the common ones!)
2. Configure the ViewRenderer Action helper for the location of Module specific templates/helpers/filters
You almost have the first right - but you probably only need to "addScriptPath()" for _Elements. Adding a Module specific script path in the bootstrap won't help unless you add all Modules, and that of course is going to result in template name collisions down the line.
The trick is in 2. - configure the ViewRenderer to dynamically add a Module's view directory at runtime. Something like what Begby suggested is pretty standard:
Code: Select all
require_once 'Zend/View.php';
require_once 'Zend/Controller/Action/HelperBroker.php';
require_once 'Zend/Controller/Action/Helper/ViewRenderer.php';
$view = new Zend_View;
// add common directories for all Views; always "add", never "set"
$this->view->addScriptPath(MC2_Bag::getBaseDir() . DS . 'views/_elements')
->addHelperPath(MC2_Bag::getBaseDir() . DS . 'views/_helpers')
->addFilterPath(MC2_Bag::getBaseDir() . DS . 'views/_filters');
$viewRenderer = new Zend_Controller_Action_Helper_ViewRenderer;
$viewRenderer->setView($view);
// set the Module specific ScriptPath syntax; The Module name is substituted and add to
// as an additional View ScriptPath when a Controller is executed
$viewRenderer->setViewBasePathSpec(MC2_Bag::getBaseDir() . DS . 'views/:moduleDir');
Zend_Controller_Action_HelperBroker::addHelper($viewRenderer);
I can't test this right now, but this should be workable. It's unavoidable that ViewRenderer will also add extra Module specific filter/helper locations based on the ViewBasePathSpec - I don't think this causes a problem really, and if it does you can subclass ViewRenderer's initView() method to fix fairly simply.