cancel
Showing results for 
Search instead for 
Did you mean: 

How to determine url path

SOLVED

How to determine url path

Hello Alan,

 

I want to create separate a new 404 page if product id not exists. I have created a new NoRouteHandler. In this new handler Process method what is  the correct way in Magento 2 if i have to determine that URL path is catalog/product/view/id/1.  I have done the following code in that i can get Moduel name and Controller name. But here i am not getting action name as "view". instead i am getting "noroute" as action name.  Is there any other way to do this?

 

class NoRouteHandler implements \Magento\Framework\App\Router\NoRouteHandlerInterface
{
    public function process(\Magento\Framework\App\RequestInterface $request)
    {
        $module = $request->getModuleName();
        $controller = $request->getControllerName();
        $action = $request->getActionName();
    }
}
-----
Darshan, Solution Consultant
Problem solved? Click Accept as Solution!
1 ACCEPTED SOLUTION

Accepted Solutions

Re: How to determine url path

Did Brent's reply answer you question? Can we mark this as resolved?

View solution in original post

4 REPLIES 4

Re: How to determine url path

Here is a great How To article to accomplish your task

 

http://inchoo.net/magento/custom-router-in-magento/

 

 

Magento Moderator since 2009
Keep Calm and Clear Cache!

Re: How to determine url path

Hi @Brent W Peterson,

 

Thanks, but this article is for Magento 1.x.

I want to do this task in Magento 2.

-----
Darshan, Solution Consultant
Problem solved? Click Accept as Solution!

Re: How to determine url path

I am assuming you have already read this article on Routing in Magento2?

 

http://inchoo.net/magento-2/routing-in-magento-2/

 

Magento Moderator since 2009
Keep Calm and Clear Cache!

Re: How to determine url path

Did Brent's reply answer you question? Can we mark this as resolved?