Before I forget to do this again I'm going to make a post on how to get the current Module, Controller, and Action while inside a View Script or Layout Script.
Here is the most correct way to do it:
-
$front = Zend_Controller_Front::getInstance();
-
$request = $front->getRequest();
-
-
$module = $request->getModuleName();
-
$controller = $request->getControllerName();
-
$action = $request->getActionName();
Now, here is the incorrect way I attempted to do this the first time:
-
$front = Zend_Controller_Front::getInstance();
-
$request = $front->getRequest();
-
-
$module = $request->getParam('module');
-
$controller = $request->getParam('controller');
-
$action = $request->getParam('action');
I found some odd behavior because sometimes while in the default module it would return default, but other times it would return a null. I'm not sure if this is a bug or not, but the most sure way to retrieve the desired result is using the appropriate methods of getModuleName(), etc.
Hope this helps someone out there!
Related Posts
- MySQL - Does Table Exist w/o Throwing Errors There are times where you would like to know if a table exists before executing an query. Most solutions require having MySQL throw an error saying "table does not exist," but I prefer a cleaner way. I found on this forum post a clean way to do it: PLAIN TEXT...
- PHP Singletons, Sub-Classing, and HAS-A Relationships I've been very busy these last fews weeks and have neglected making any posts. While there are a variety of subjects I'd love to post about, they'll most likely have to wait until the next year. However, I thought I might be able to throw up a quick example of...
- PHP Design - Biggest Database Oversights Over the last three years I've had the opportunity to work on several PHP projects, some of them having grown rapidly and required to scale quickly. Three in particular have been a fantastic learning experience for me. Now I don't consider myself a total expert, but I thought I would...

Testing new spam comment filter.