Before I converted my Zend Framework application to a module based structure, it had a single layout and I could pass variables to it from my controller like so:
// Controller action
$this->view->foo = 'Something';
// Layout
<?= $this->foo ?>
However, since moving everything into a default module and creating a separate "admin" module, I can no longer get this to work, most likely due to me moving my "View Settings" out of my bootstrap file and into the controller plugin where I am switching the layout based on the module. My plugin looks like this:
class KW_Controller_Plugin_LayoutSelector extends Zend_Controller_Plugin_Abstract
{
public function preDispatch(Zend_Controller_Request_Abstract $request)
{
$layout = Zend_Layout::getMvcInstance();
$layout->setLayout($request->getModuleName());
$view = $layout->getView();
$view->doctype('HTML5');
$view->setEncoding('UTF-8');
$view->headMeta()->appendHttpEquiv('Content-Type', 'text/html; charset=UTF-8');
$view->headScript()->appendFile('/js/jquery-1.7.1.min.js');
switch ($request->getModuleName()) {
case 'admin':
$view->headTitle('Admin Area')->setSeparator(' - ');
$view->headLink()->appendStylesheet('/css/admin/global.css');
$view->headScript()->appendFile('/js/admin/common.js');
break;
default:
$view->headTitle('Main Site')->setSeparator(' - ');
$view->headLink()->appendStylesheet('/css/global.css');
$view->headScript()->appendFile('/js/common.js');
break;
}
}
}
If I move all of those method calls to the view back into my bootstrap, I can pass variables to the layout again; so I'm guessing that something is happening in the wrong order, maybe my layout is being switched after I have passed the variables to the view from my controller and they're not making it into my layout? (I've tried changing the point at which the above runs by putting the code in both preDispatch() and postDispatch(), etc.)
It's worth noting, that I can access these variables in my individual view scripts, just not the layout that they're contained within.
Any pointers would be greatly appreciated.