If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

How to create custom router?

Greeting! It’s time to share our knowledge on how to create custom router, as many of us use the standard router. You should know that Magento has four types of the routers: admin, standard, cms and default – they are loading in the order we’ve described. But, have you ever faced with such configuration?

Yes, if you look to standard code, that means – Magento will use the standard router for processing requests and URLs, and when you follow magento.dev/test-frontname URL, in this case, Magento says for the standard router that it should take action indexAction from IndexController from module Atwix_Test – it is not so complicated, we guess. Actually, when the requests come to Magento, then it calls all routers till one of them will response – otherwise, there 404 page will be displayed.

Now, let’s start creating own router. First of all, we need to declare router in config.xml:

The previous code explains Magento that it should transmit control to the indexAction function which is placed in app/code/local/Atwix/Test/controllers/IndexController.php., and your router will be called after admin and standard, but if these routers do not respond for the requests – then your router will be called.
So, now you can check request, proceed it and show page you want before Magento will throw “Not found” page. Hope that simple tutorial will be useful. We are waiting for your comments and happy, non-crappy coding!

To create a router first you need to add it to the \Magento\Framework\App\RouterList, which is transferred to the Front Controller and contains all the available routers in the right order. To do this, we use the di.xml file in our module. After that we need to create a CustomRouter class.

Custom Router. To do a switch first you need to add it to the \Magento\Framework\App\RouterList, which is traded to the Front Controller and contains all the available switches composed fittingly. To do this, we use the di.xml record in our module. After that we need to make a CustomRouter class.

Magento Expert Forum is not affiliated with or endorsed by the Magento Ecommerce Project. This forum is set up to share magento skills together. If you have any question or project request, please Contact Us