2 Comments

Custom module dynamic action controller

cybersource tokenization & magento communication [closed]
Magento 2 set cookie on a phtml file

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
    }
}

Related Posts

  • How to use Ajax on backend side? (0)
    Building a module to control brands (simple backend module). Already created all the elements and now I'm trying to create an ajax request but i'm not sure how should i do it and where the ajax controller should be placed. Should I for backend create ajaxController inside adminhtml […]
  • How to map a dynamic url to a function in controller (1)
    I'm creating a new magento module. The frontend name of the module is groupedproduct. Now i need to map a dynamic url to indexAction of the IndexController. For example the url will of the form http://localhost/magento/groupedproducts/subcat1 This url will be dynamic for example […]
  • Optimize magentos controller action URL (1)
    How to cut short the URL of a controller action page in magento2 For instance: If custom modules controller page is in : Vendor/Module/Controller/Index/Index.php in routes.xml: I had defined frontname as : i Instead of navigating to : localhost/magento/i/index/index How to […]
  • Optimize magentos controller action URL (1)
    How to cut short the URL of a controller action page in magento2 For instance: If custom modules controller page is in : Vendor/Module/Controller/Index/Index.php in routes.xml: I had defined frontname as : i Instead of navigating to : localhost/magento/i/index/index How to […]
  • Optimize magentos controller action URL (1)
    How to cut short the URL of a controller action page in magento2 For instance: If custom modules controller page is in : Vendor/Module/Controller/Index/Index.php in routes.xml: I had defined frontname as : i Instead of navigating to : localhost/magento/i/index/index How to […]
  • How to generate formkey in Magento and send a POST request? (1)
    Magento uses some sort of form key to send POST data. I want to send POST data to a controller in Magento and receive it. How do I do that?
  • How to generate formkey in Magento and send a POST request? (1)
    Magento uses some sort of form key to send POST data. I want to send POST data to a controller in Magento and receive it. How do I do that?
  • Add custom dynamic field to (configurable) product page (0)
    How would I go about making a custom dynamic field on a product page? Like this (red box): It looks rather simple but I haven't figured it out yet. Any help would be appreciated!
  • Create Simple Controller Not Working In My Module in Magento 1.9.2? (2)
    I am Trying To create a Simple Module. It's Found 404 page Error. My config file in app/etc/modules/Codefire_Mymodule.xml <?xml version="1.0"?> <config> <modules> <Codefire_Mymodule> <actve>true</actve> […]
  • Public actions in admin controllers (2)
    I've discovered that in the class MagentoBackendAppAbstractAction (the ancestor of every admin controller action) there is a member called _publicActions that is used in the validation of the secret key like this: if (is_array($this->_publicActions) && […]
cybersource tokenization & magento communication [closed]
Magento 2 set cookie on a phtml file

2 Comments on this article

  • User November 12, 2016

    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;
        }
    }
    

    Reply

  • User November 12, 2016

    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':
                 $this->_forward('product');
                 break;
            case 'sale':
                 $this->_forward('sale');
                 break;
            /* 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.

    Reply

Add a comment

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax