Hello Magento Friends,
In today’s Magento 2 Tutorial Blog, I am going to justify How to Get Controller of Each Request in Magento 2.
Controller in Magento 2 is a file located at a specific place and it responds to a specific URL. If you want to get and print the name of each controller that is called at a specific request, then you need to follow the below steps.
Step 1: Create a file at the below path
app\code\Vendor\Extension\etc\events.xml
Now, add the following code
<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd"> <event name="controller_action_predispatch"> <observer name="custom_observer" instance="Vendor\Extension\Observer\ControllerActionPredispatch" shared="false" /> </event> </config>
Step 2: Create a file at the following path
app\code\Vendor\Extension\Observer\MyClass\ControllerActionPredispatch.php
Then, add the below-mentioned code
<?php namespace Vendor\Extension\Observer; use Magento\Framework\Event\ObserverInterface; class ControllerActionPredispatch implements ObserverInterface { public function execute(\Magento\Framework\Event\Observer $observer) { // insert code here } }
Accordingly, you can easily Get Controller of Each Request in Magento 2. Get User Data Inside Controller in Magento 2. In case of any difficulty, let me know via the comment section. Share the article with others and stay in the know.
Happy Coding!
In this article, we will learn about how to get database value in the Shopify…
Tailwind CSS has emerged as a powerful utility-first CSS framework, offering developers a unique approach…
The mobile app development field has witnessed a rapid revolution over the past few years.…
Hello Magento mates, Today we will learn to add a call JS on the checkout…
Business survival in today’s digital world has become extremely difficult. Using traditional marketing techniques is…
Are you setting up a payroll system for your eCommerce startup? Ensuring compliance with myriad…