0

Magento ver. 2.3.2

I am writing a Magento 2 module. I'm trying to re-write a CMS page URL:

https://www.test.com/url-test/cat1/cat2/cat3/

https://www.test.com/url-test?path=/cat1/cat2/cat3/

I have a widget on the CMS page url-test that handles the logic of what is passed in GET['path'].

I cannot get the Router to fire at all (display the die() cmd). I've played with different values for the di sortOrder. I've tried overriding default routers. All to no avail.

I don't have a /etc/frontend/routes.xml file as I don't think I need it.

/etc/frontend/dii.xml:

<?xml version="1.0"?>
<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="test_router" xsi:type="array">
                    <item name="class" xsi:type="string">Me\MyModule\Controller\Router</item>
                    <item name="disable" xsi:type="boolean">false</item>
                    <item name="sortOrder" xsi:type="string">1</item>
                </item>
            </argument>
        </arguments>
    </type>
</config>

/Controller/Router.php:

namespace Me\MyModule\Controller;

class Router implements \Magento\Framework\App\RouterInterface
{
    private $actionFactory;

   public function __construct(\Magento\Framework\App\ActionFactory $actionFactory)
    {
        $this->actionFactory = $actionFactory;
    }

    public function match(\Magento\Framework\App\RequestInterface $request)
    {
        die("test Router");
        $pathInfo = $request->getPathInfo();

        return null;
    }
}
0

die() will not work. Use logger concept.

This is the wrong files name etc/frontend/dii.xml it should be etc/frontend/di.xml.

using SortOrder value 1 is very dangerous.

In this case routing should be between 60(cms route) and 100 (default route).

See https://devdocs.magento.com/guides/v2.3/extension-dev-guide/routing.html

  • facepalm! di.xml fixed it – Michael Aug 22 at 11:13

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.