0

I want to create some public pages with dynamic URL, if I write code like execute($id){} abc.com/plugin/controller/action/some_id

How to possible this things in M2?

1 Answer 1

1

As per the provided URL

abc.com/plugin/controller/action/some_id

some_id would be the parameter right? you can use it as it is and get it from the $this->request->getParam('some_id') object and render the page.

By default in Magento, you call also use the same URL to render the page with the response and result object.

If you want to use some other dynamic url you can also create a custom router. with di.xml

create file module-name/etc/frontend/di.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="plugin" xsi:type="array">
                    <item name="class" xsi:type="string">ABC\Module\Controller\Router</item>
                    <item name="disable" xsi:type="boolean">false</item>
                    <item name="sortOrder" xsi:type="string">60</item>
                </item>
            </argument>
        </arguments>
    </type>
</config>

and then create a controller class wich implements

\Magento\Framework\App\RouterInterface and with match() function in this class to use your own route matching logic.

For more referance, you can refer the https://devdocs.magento.com/guides/v2.4/extension-dev-guide/routing.html#custom-routers

Your Answer

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

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