Home » Magento, Magento 216 May 2016

Magento 2: Get Controller, Module, Action & Route Name

This article shows how we can get name of the current module, controller name, action name and route name in Magento 2.

Using Dependency Injection (DI)

Below is a block class of my custom module (Chapagain_HelloWorld). I have injected object of \Magento\Framework\App\Request\Http class in the constructor of my module’s block class.

app/code/Chapagain/HelloWorld/Block/HelloWorld.php

See more functions in vendor/magento/framework/App/Request/Http.php.

Now, we use can the function in our template (.phtml) file.

Using Object Manager

Hope this helps. Thanks.

Magento 2

Get New Post by Email

Find me on

FacebookTwitterGoogle+LinkedInRSS Feed

Comments are closed.