How to make my ZF2 module load other layout file for specific controller ?
Consider you have IndexController
and AdminController
in your ZF2 application module and the IndexController
is using layout.phtml but you want to use adminlayout.phtml for AdminController
.
How is it possible?
other best Solution :
change YOURMODULENAME to your module specific name
and don't forget to register your new controller by adding this config in your module config file:
Rather than adding logic to your entire module in the
onBootstrap
method, you can use your controller'sonDispatch
method to simply set the layout for that entire controller.In your admin controller, add a shortcut at the top:
Then, use the following
onDispatch
in your controller:I believe this solution is better because the code only gets called when the admin controller is called.