odd_duck
odd_duck

Reputation: 4111

Magento - How to extend Front Controller

I am need of making a change to the Magento function _checkBaseUrl found within:

app/code/core/Mage/Core/Controller/Varien/Front.php

As best practice I am trying to extend it with my own module so I am not editing the core code and files but it is not working. If I make the change in the core file i get the desired response but when using this it doesn't work. My module is showing up as Enabled in Configuration > Advanced > Advanced

Files are as below:

etc/modules/Me_Coreextend.xml

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <modules>
        <Me_Coreextend>
            <active>true</active>
            <codePool>local</codePool>
        </Me_Coreextend>
    </modules>
</config>

app/code/local/Me/Coreextend/etc/config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Me_Coreextend>
            <version>1.0</version>
        </Me_Coreextend>
  </modules>
    <frontend>
        <routers>
            <core>
                <args>
                    <modules>
                         <Me_Coreextend before="Mage_Core">Me_Coreextend</Me_Coreextend>
                    </modules>
                </args>
            </core>
        </routers>
    </frontend>
</config>

app/code/local/Me/Coreextend/Controller/Varien/Front.php

I am including only the _checkBaseUrl function in this file not the whole contents of app/code/core/Mage/Core/Controller/Varien/Front.php - is this correct? (I have tried to include it all as well but that still doesn't work either)

include_once('Mage/Core/Controller/Varien/Front.php');
class Me_Coreextend_Controller_Varien_Front extends Mage_Core_Controller_Varien_Front
{
    protected function _checkBaseUrl($request)
    {
        // custom changes...
    }
}

Is there anything I am doing wrong?

Upvotes: 2

Views: 847

Answers (2)

Cristiano Casciotti
Cristiano Casciotti

Reputation: 1026

You cannot extend Magento's Front Controller because isn't a "standard" service controller (notice that is in the Controller folder and not in the controllers one). As you can see in Mage_Core_Model_App class in _initFrontController method called by run method:

$this->_frontController = new Mage_Core_Controller_Varien_Front();

You can only copy the file in your project's local folder:

app/code/local/Mage/Core/Controller/Varien/Front.php

and safely edit the file according to your business requirements.

Upvotes: 2

Chirag Nandaniya
Chirag Nandaniya

Reputation: 495

Magento not providing functionality for overwrite controller files in folder "Controller", you can only overwrite controller files which are in "controllers" folder

simply you just copy your file to load

app/code/local/Mage/Core/Controller/Varien/Front.php

Upvotes: 0

Related Questions