---
title: "How to Override Custom Module's Controller file in Magento 2"
url: "https://magecomp.com/blog/override-custom-modules-controller-file-in-magento-2/"
date: "2018-05-10T16:40:54+00:00"
modified: "2025-06-05T12:33:57+00:00"
author:
  name: "Dhiren Vasoya"
  url: "https://magecomp.com/"
categories:
  - "How To"
  - "Magento 2"
word_count: 329
reading_time: "2 min read"
summary: "Understanding that each business has its own story, to give a personalized touch to store always ends up with customization &amp; development. Over the time Magento has topped Ecommerce CMS list wi..."
description: "Having tons of extension installed in Magento store sometimes creates confliction with another extension at that time to fix it quickly. You need to override..."
keywords: "How To, Magento 2"
language: "en"
schema_type: "Article"
related_posts:
  - title: "How to Redirect to a Particular Page After Login in Magento 2"
    url: "https://magecomp.com/blog/redirect-to-a-particular-page-after-login-magento-2/"
  - title: "What’s the difference between Allowed Countries, EU Countries, and Top Destinations in Magento?"
    url: "https://magecomp.com/blog/difference-between-allowed-eu-and-top-countries-in-magento/"
  - title: "How to Add Pagination in Custom Collection of Magento 2?"
    url: "https://magecomp.com/blog/add-pagination-in-custom-collection-magento-2/"
---

# How to Override Custom Module's Controller file in Magento 2

_Published: May 10, 2018_  
_Author: Dhiren Vasoya_  

![Overriding Custom modules controller in Magento2](https://magecomp.com/blog/wp-content/uploads/2018/05/Overriding-Custom-modules-controller-in-Magento2-1024x332.webp)

Understanding that each business has its own story, to give a personalized touch to store always ends up with customization & development. Over the time Magento has topped Ecommerce CMS list with its functionality, features and power of extending the native functionalities. Compared to Magento 1, In Magento 2 overriding and manipulating with classes is becoming easier a developer to play quickly. At MageComp, we have never recommended modifying default core functionalities, but we can extend core functionalities using concepts of overriding which is a safe and easy way to achieve customization or development.

[![Magento 2 Speed & Performance Optimization Services](https://magecomp.com/blog/wp-content/uploads/2025/02/Magento-2-Speed-Performance-Optimization-Services-CTA-1.webp)](https://magecomp.com/magento-performance-optimization.html)

The extension plays an important role to achieve customization in Magento 2 but when there are tons of extensions installed within a store environment it creates conflicts with other extensions. At that time to quickly get rid of the problem, the easiest solution comes to mind is to override custom extension controller file. By default, there are [three different ways to override core functionalities](https://magecomp.com/blog/override-core-code-using-custom-plugin-magento-2/). Today we will use preference method to override any custom module controller into your extension.

[![hyva theme development](https://magecomp.com/blog/wp-content/uploads/2025/02/hyva-theme-development-CTA-1.webp)](https://magecomp.com/services/hyva-theme-development/)

**Step 1:** First, we need to create **“di.xml”** file inside extension the below directory

**app\code\Vendor\Extension\etc**

```
<?xml version="1.0"?><br></br><config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"><br></br>    <preference for="CustomvendorCustomextensionControllerAdminhtmlCustomcontrollerCustomaction" type="VendorExtensionControllerAdminhtmlCustomcontrollerCustomaction" /><br></br></config>
```

**Step 2:** after that, you need to create **“Customaction.php”** file inside extension the below directory

**app\code\Vendor\Extension\Controller\Adminhtml\Customcontroller**

```
<?php <br></br>namespace VendorExtensionControllerAdminhtmlCustomcontroller;<br></br>use MagentoBackendAppActionContext;<br></br><br></br>class Customaction extends CustomvendorCustomextensionControllerAdminhtmlCustomcontrollerCustomaction<br></br>{<br></br>    public function __construct(Context $context)<br></br>    {<br></br>        // YOU NEED TO PASS ALL THE OBJECT WHICH USER BY PARENT CONTROLLER CONSTRUCT FUNCTION.<br></br>        parent::__construct($context);<br></br>    }<br></br>    protected function Customaction()<br></br>    {<br></br>        // ADD YOUR CUSTOM CODE HERE<br></br>    }<br></br>}
```

If you face any issue while implementing this code comment down below. We will help you to fixed it asap. Happy Coding!

[![Hire Magento Programmer](https://magecomp.com/blog/wp-content/uploads/2025/02/Hire-Magento-Programmer-CTA-1.webp)](https://magecomp.com/services/hire-magento-programmer/)


---

_View the original post at: [https://magecomp.com/blog/override-custom-modules-controller-file-in-magento-2/](https://magecomp.com/blog/override-custom-modules-controller-file-in-magento-2/)_  
_Served as markdown by [Third Audience](https://github.com/third-audience) v3.5.3_  
_Generated: 2026-03-13 06:26:46 UTC_  
