I posted a question earlier but didn't able to understand the answer,
Magento 2: How to create a dynamic url with the same controller
i want to create a page with the dynamic url but with same controller to handle the requests,
for example: http://192.168.1.108/magento2/profile/id/jatin123
and http://192.168.1.108/magento2/profile/id/amit123
just able to get the id and display the results accoring to the id = "jatin123" display this user profile and id="amit123" display this user profile.
Please suggest a solution.
Best Answer
You can create it by with the help of
Magento\Framework\App\RouterList
. For this you need to createdi.xml
in your module (I am assuming that you know how to create module in M2). First createdi.xml
in below path,app/code/yourvendor/yourmodule/etc/frontend/di.xml
In this file add
Now create a
YOURVENDOR\YOURMODULE\Controller\Router
but make sure that It shouldImplements
\Magento\Framework\App\RouterInterface
Alternatively you can also take help from
Magento_Cms
module. Magento team also doing the same.Reference
app\code\Magento\Cms\etc\frontend\di.xml
and
app\code\Magento\Cms\Controller\Router.php