I'm trying to set up a function so that I can get the pages current controller from within a layout. Because $this->getRequest()->getControllerName() cannot be used in layout I was looking for a way to use it somewhere else and then set it in the registry. However I've never used the registry and beyond setting and then calling both in the layout, I cannot seem to get it to work.
Perhaps there is a command I'd be able to use straight from the layout to do this? If not then I'd need help setting a registry value as a bootstrap.
sounds like a bad idea.
why not inject data you want from controller into layout/view ?
Then I'd have to remember to initialize it in every controller I create or else it fails. Whats wrong with bootstrapping this? I know that this sort of stuff is common practice, however I have not messed with bootstrapping or the registry so I am having trouble with it.
"$this->getRequest()->getControllerName()" , so you want a name of controller. just inject that into your view/layout from action method.
"Then I'd have to remember to initialize it in every controller", your controller should have a common parent. so you can inject that name from parent contructor method.
this is a common practise for zendframe programming. we have a common parent class for all controllers.
make a parent class:
myAppController extends Zend_Controller_Action
then when need an error controller, we do like this:
ErrorController extends myAppController
"Whats wrong with bootstrapping this", in bootstraping code, how do you know which page is going to be viewed by a vistor / how do you know which controller is used?
for example: In errorController, your need a name of error controller, in newsController, you your need a name of news controller.