Step 1:
Create di.xml file at app/code/[Name space]/[Your Module]/etc
1 2 3 4 |
<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/ObjectManager/etc/config.xsd"> <preference for="Magento\Cms\Controller\Index\Index" type="[Name Space]\[Your Module]\Controller\Cms\Index" /> </config> |
In this example, we will rewrite controller Magento/Cms/Controller/Index/Index. In which, [Name Space]\[Your Module]\Controller\Cms\Index will be used to override Magento\Cms\Controller\index\Index –the homepage in original Magento 2.
Step 2: Define an overriding controller class
You need to create Index.php in app/code/[Name Space]/your Module]/Controller/Index
1 2 3 4 5 6 7 8 9 10 11 |
<?php namespace [Name Space]\[Your Module]\Controller\Index; class Index extends \Magento\Cms\Controller\Index\Index { public function execute($coreRoute = null) { // todo } } |
Done! I’m sure that you can follow this tutorial without any difficulty.
If you want get query string params in controller file,...
Create di.xml and add the below code Magemonkey/Redirect/etc/frontend/di.xml [crayon-62865c168d927707772114/] Create...
You can try below code to change local date to...
Step 1: First you need to add registration.php file in...
Step1 : Override message.js in current theme file on the...