3 (60%) 8 votes

Hi guys,

I want to share you this post to guide you through Magento 2 controller override. In fact, it’s quite easy to Overriding a controller in Magento 2 with my method. So let’s start!

How to Overriding A Controller Magento 2

You need to follow these steps to everiding a controller in Magento 2:

  • Step 1:
  • Step 2:
  • Step 3:

Step 1: Create file di.xml file in app/code/[Name space]/[Your Module]/etc

Create file di.xml file in app/code/[Name space]/[Your Module]/etc

This example I want to rewrite controller Magento/Cms/Controller/Index/Index

[Name Space]\[Your Module]\Controller\Cms\Index will be used to override Magento\Cms\Controller\Index\Index, which is the homepage in original Magento 2.

Step 2 –  Defining an overriding controller class

Such a long post, right? But don’t worry we are almost finish with Magento 2 controller override:

Defining an overriding controller class

Create Index.php in app/code/[Name Space]/[Your Module]/Controller/Index

Step 3:  Done!

Thank you!

In case you want to fully experience its new awesome features, please try the Magento 2 Demo here. And of course, please feel free to find more Magento 2 Tutorials by our Experts.

Your Magento website needs a powerful Magento ERP for stock control.


magento erp

Fix 403 Forbidden Error in Magento 2
Orders Have The Same "extension_attributes" Value On the API Magento 2

Leave a Reply

Your email address will not be published. Required fields are marked *