Magento 1.9 Module – Custom Dynamic Action Controller

actioncontrollersmagento-1.9module

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

UPDATE

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

<frontend>
        <routers>
            <marketshop>
                <use>standard</use>
                <args>
                    <module>Myname_Mymodule</module>
                    <frontName>market</frontName>
                </args>
            </marketshop>
        </routers>
    </frontend>

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(){
        $this->loadLayout();
        $this->renderLayout();
    }
    public function globalAction(){
        // I want all action comes here and doing somethings
        // their not have any 404 page
    }
}

Best Answer

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

<events>
    <controller_front_init_routers>
        <observers>
            <market>
                <class>Myname_Mymodule_Controller_Router</class>
                <method>initControllerRouters</method>
            </market>
        </observers>
    </controller_front_init_routers>
</events>

Then create the class Myname_Mymodule_Controller_Router.

<?php 
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()) {
            Mage::app()->getFrontController()->getResponse()
                ->setRedirect(Mage::getUrl('install'))
                ->sendResponse();
            exit;
        }
        $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') {
                 $request->setModuleName('marketshop')  
                     ->setControllerName('index')
                     ->setActionName('global');
                 $request->setAlias(
                     Mage_Core_Model_Url_Rewrite::REWRITE_REQUEST_PATH_ALIAS,
                     $pathInfo
                 );
                return true;
            }
        }
        return false;
    }
}