Keith V
Keith V

Reputation: 730

Magento: Controller override not working

Attempting to override the Cms/controllers/IndexController.

This is the directory structure of my module -

The code for my IndexController is

<?php

require_once 'Mage'. DS .'Cms'. DS .'controllers'. DS .'IndexController.php';

class MyCompany_FourOhFourExp_IndexController extends Mage_Cms_IndexController
{
    public function noRouteAction($coreRoute = null){
        Mage::log('First Function');
        header("Location: new_route.html");
        die();
    }

    public function defaultNoRouteAction()
    {
        Mage::log('Second function!');
        header("Location: new_route.html");
        die();
    }
}
?>

and this is the code for my config.xml file

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <modules>
        <MyCompany_FourOhFourExp>
            <version>0.1.0</version>
        </MyCompany_FourOhFourExp>
    </modules>
    <frontend>
        <routers>
            <cms>
                <args>
                    <modules>
                        <MyCompany_FourOhFourExp before="Mage_Cms">MyCompany_FourOhFourExp</MyCompany_FourOhFourExp>
                    </modules>
                </args>
            </cms>
        </routers>
        <events>
            <controller_action_noroute>
                <observers>
                    <cms>
                        <class>cms/observer</class>
                        <method>noRoute</method>
                    </cms>
                </observers>
            </controller_action_noroute>
    </frontend>
</config>

Hoping someone can explain why this isn't overriding. I've looked through numerous tutorials and blog posts but have yet to figure out why it doesn't work.

Upvotes: 1

Views: 1686

Answers (2)

Alex
Alex

Reputation: 767

What need to do:

  • add to app/code/local/Mage/Cms/controllers/IndexController.php , Mage::dispatchEvent('cms_controller_action_noroute', array('action'=>$this));

  • in your custom module, catch the Event

Upvotes: 0

Amit Bera
Amit Bera

Reputation: 7611

There are lot of issue:

1)Modulepath:

As your controller class is MyCompany_FourOhFourExp_IndexController then path of class should be

app/code/local/MyCompany/FourOhFourExp
  1. Local/MyCompany/controllers/IndexController

  2. Local/MyCompany/etc/config.xml

change to

  1. Local/MyCompany/FourOhFourExp/controllers/IndexController/php
  2. Local/MyCompany/FourOhFourExp/etc/config.xml

2)Mage cms controller donot add properly

require_on Mage::getModuleDir('controllers', 'Mage_Cms'). DS .'IndexController.php'; 

Upvotes: 2

Related Questions