Looking for someone to let me know how grab the action name from a Module Core Controller and instead of executing an action use the action name as a variable for determine which content to output.
Basically, I am switching over to SocialEngine instead of my wordpress install and in order to keep my old page structure I am setting up modules for pulling page output. So, I setup a Controller for sculptures and then each sculpture data is stored in a database table.
So when someone goes to MyDomain/sculptures they would get a list pulled from the database that would dynamically generate the urls for navigating to the individual sculpture page... which would, of course, be MyDomain/scultures/sculpturename
Which would normally execute the public function sculpturenameAction() function in the controller, however, I would like to intercept the action name and execute a different function that would provide the data for the individual sculpture page based upon the action name.
Is this possible? How would I do it?
You can get the current module, controller and action name using below code:
$front = Zend_Controller_Front::getInstance();
$module = $front->getRequest()->getModuleName();
$controller = $front->getRequest()->getControllerName();
$action = $front->getRequest()->getActionName();
If you want to divert the route or want to run some other code at some action than you can use the routeShutdown() method. Please see the below example for this:
class yourModuleName_Plugin_Core extends Zend_Controller_Plugin_Abstract {
public function routeShutdown(Zend_Controller_Request_Abstract $request) {
$module = $request->getModuleName();
$controller = $request->getControllerName();
$action = $request->getActionName();
//ADD YOUR ACTION CONDITION
if ($module == 'core' && $controller == 'index' && $action == 'index') {
//SET SOME OTHER ACTIONS OR YOU CAN WRITE SOME OTHER CODE
$request->setModuleName('yourModuleName');
$request->setControllerName('yourControllerName');
$request->setActionName('yourActionName');
}
}
}
Hope this answer will helps you. Thank you !!