1

I am trying to build a module that has a custom front-end router on magento 2.1.12. I am following magento doc & I am using the inchoo custom router example.

The problem is the route (MY-SITE/matinteg/orders) throws

Front controller reached 100 router match iterations

error when ever I try to reach it. I tried to flush & remove cache, cache_page, progress, ... so it doesn't seem to be mis-configured or problematic cache. I also upgrade, compile, deploy & flush cache so many time. But there was no luck.

The $request returns a complete object and everything seems to be true, but still I get the error.

I have

vendor_module/Controller/Router.php

public function match(\Magento\Framework\App\RequestInterface $request){
    if($request->getModuleName() == 'cms'){
        $identifier = trim($request->getPathInfo(), '/');
        if(strpos($identifier, 'matinteg/orders') !== false) {
            /*
             * We must set module, controller path and action name for 
               our controller class(Controller/Test/Test.php)
             */
            $request->setModuleName('cms')->setControllerName('integration')->setActionName('integration');
        } else {
            //There is no match
            return;
        }
        /*
         * We have match and now we will forward action
         */
        return $this->actionFactory->create(
            'Magento\Framework\App\Action\Forward',
            ['request' => $request]
        );            
    }
}

The rest of the files are pretty identical to inchoo sample. I have

vendor_module/Controller/Integration/Integration.php

vendor_module/etc/frontend/routes.xml

I tried to hire the solution in this stack but it was not helpful either

2 Answers 2

2

Below code might be resolve the issue

public function match(\Magento\Framework\App\RequestInterface $request){
    if($request->getModuleName() == 'cms'){
        return; 
    }
        $identifier = trim($request->getPathInfo(), '/');
        if(strpos($identifier, 'matinteg/orders') !== false) {
            /*
             * We must set module, controller path and action name for 
               our controller class(Controller/Test/Test.php)
             */
            $request->setModuleName('cms')->setControllerName('integration')->setActionName('integration');
        } else {
            //There is no match
            return;
        }
        /*
         * We have match and now we will forward action
         */
        return $this->actionFactory->create(
            'Magento\Framework\App\Action\Forward',
            ['request' => $request]
        );            

}
0
1

A better way could be

public function match(\Magento\Framework\App\RequestInterface $request){

if (!$this->dispatched) {
    $identifier = trim($request->getPathInfo(), '/');

    if (strpos($identifier, 'matinteg/orders') !== false) {
        $request->setModuleName('cms')->setControllerName('integration')->setActionName('integration');
    } else {
        return false;
    }

    $request->setDispatched(true);
    $this->dispatched = true;

    return $this->actionFactory->create(
        'Magento\Framework\App\Action\Forward',
        ['request' => $request]
    );
}}
1
  • I don't see how adding setDispatched(true) or manually setting it to true would make any difference,... looking at the FrontController.php code (the original Magento 2), it would (1) call your "match" function to get direction, and (2) perform "processRequest", ... inside this function it already has (setDispatched(true)) at the first line, but then after going further in execution it's setting back to "false" due to something not right, which I am working on investigating at the moment. But having your 2 lines in the middle has no effect whatsoever. Sep 23, 2019 at 16:46

Your Answer

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

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