3

I created a custom router

this is my di.xml

<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
 * Copyright © 2016 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Framework\App\RouterList">
        <arguments>
            <argument name="routerList" xsi:type="array">
                <item name="default" xsi:type="array">
                    <item name="class" xsi:type="string">Vendor\Custom\Controller\Router</item>
                    <item name="disable" xsi:type="boolean">false</item>
                    <item name="sortOrder" xsi:type="string">40</item>
                </item>
            </argument>
        </arguments>
    </type>
</config>

This is the block match function:

public function match(\Magento\Framework\App\RequestInterface $request) {
        $identifier = trim($request->getPathInfo(), '/');

        if(strpos($identifier, 'search') !== false) {

            $request->setModuleName('catalogsearch')->setControllerName('result')->setActionName('index');
        } 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]
        );
    }

Everything is fine till I got an error "Front controller reached 100 router match iterations" everytime I go to a 404 page.

  • what is the url of your 404 page ? – Yash Shah Apr 22 at 4:48
  • cms/noroute/index this is working, but when I get to example.com/any-inexistent-path, the error takes place – xdev Apr 22 at 13:37
0

Set return null in your else condition :

public function match(\Magento\Framework\App\RequestInterface $request) {
        $identifier = trim($request->getPathInfo(), '/');

        if(strpos($identifier, 'search') !== false) {

            $request->setModuleName('catalogsearch')->setControllerName('result')->setActionName('index');
        } else {
            //There is no match
            return null;
        }

        /*
         * We have match and now we will forward action
         */
        return $this->actionFactory->create(
                        'Magento\Framework\App\Action\Forward', ['request' => $request]
        );
    }
  • not working... still gives me that error – xdev Apr 21 at 20:24
0

try compile and flush cache

bin/magento setup:di:compile
 bin/magento cache:flush
  • not working, already done – xdev Apr 21 at 15:02
  • Try dump data in your condition "strpos($identifier, 'search')" I think it has problem in here – the light Apr 21 at 15:12
  • you mean to print the identifier value? – xdev Apr 21 at 20:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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