Each controller I need to define how many action can be like saleAction() , productAction() something else.

But I want to make a action who receive all action like ......Action() It's receive all request except indexAction(). Is this possible only edit controller file?

Because now my URL like http://www.example.com/controller/action/parameter I need to convert that http://www.example.com/controller/action_as_parameter/somethings_if_need


Actually I not make yet. But I want to make a simple routers like


And controllers also simple. If I can this way then I make my module or find another way

class Myname_Mymodule_IndexController extends Mage_Core_Controller_Front_Action
    public function indexAction(){
    public function globalAction(){
        // I want all action comes here and doing somethings
        // their not have any 404 page

3 Answers 3


you will need a custom router.
Add this inside the global tag in config.xml


Then create the class Myname_Mymodule_Controller_Router.

class Myname_Mymodule_Controller_Router extends Mage_Core_Controller_Varien_Router_Abstract
    public function initControllerRouters($observer){
        $front = $observer->getEvent()->getFront();
        $front->addRouter('market', $this);
        return $this;
    public function match(Zend_Controller_Request_Http $request){
        if (!Mage::isInstalled()) {
        $pathInfo = trim($request->getPathInfo(), '/');
        $params = explode('/', $pathInfo);
        //if module is market and controller is index
        if(isset($params[0]) && $params[0] == 'market' && isset($params[1]) && $params[1] == 'index') {
             //if the action is index - proceed as normal
             if (!isset($params[2]) || $params[2] == 'index') {
                 return false; //standard router will pick it up
             //if action is not index, map the request to the `globalAction`
             if (isset($params[2]) && $params[2] != 'index') {
                return true;
        return false;
  • There some problem default folder name is controllers but U use controller . I change this then it say Front controller reached 100 router match iterations. And I want when my first params is market then I use any thing in 2n to last params all are calling my global function. Mar 20, 2016 at 5:59
  • It works I have some mistake but I need to change controller to controllers Mar 20, 2016 at 6:20
  • Awesome. If I use controllers It's ok for local but when I upload online then need controller. It's I first know today. Mar 20, 2016 at 11:34

I guess you can pass a parameter to your main action method and then use a switch to forward to another action of the same controller, for example:

public function myAction() {
   $param = $this->getRequest()->getParam('param');

   switch ($param) {
        case 'product':
        case 'sale':
        /* And so on... */

public function saleAction() {

public function productAction() {

But I reckon if you're able to pass a parameter to a main action you can also change the action and access directly the action you need.

  • 1
    how can I call myAction() in my controller ?
    – Kaka
    Mar 16, 2016 at 8:39
  • 1
    Well it depends on how your module is configured, could you post both your config.xml file and your controller file ? Mar 16, 2016 at 8:41
  • Actually I want to make a simple module for this. Just add some code in my question. Mar 16, 2016 at 8:51
  • 1
    So right now your indexAction is called like this www.example.com/market/index/index if you want to call the myAction you can call www.example.com/market/index/my Mar 16, 2016 at 8:56
  • But I need to convert url www.example.com/market/index/my to www.example.com/market/mymarket or www.example.com/market/mymarket/products their mymarket need to dynamic. If there have any index or other parameters that's not feel better. Mar 16, 2016 at 9:06

You can override this method in your controller:

public function getActionMethodName($action)
    return 'indexAction';

public function indexAction()
    //action name

Then always will go to the index action, where you can use the original action name as a parameter.



Will work!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.