扩展magento核心控制器,但不工作


Extending magento core controller but not working

我正在扩展magento核心控制器,但它不能工作。它不能显示任何错误。我已经为它创建了一个模块。该模块显示在后台的system/configuration/advanced中。我有两个文件控制器等。控制器/AccountController.php:

<?php
require_once Mage::getModuleDir('controllers', 'Mage_Customer').DS.'AccountController.php';
//we need to add this one since Magento wont recognize it automatically
class Inchoo_Coreextended_Frontend_Customer_AccountController extends Mage_Customer_AccountController
{//here, you extended the core controller with our
public function indexAction()
{
parent::indexAction();
//you can always use default functionality
}
public function myactionAction()
{
//my code
//you can write your own methods / actions
}
public function mymethod()
{
//my code
//you can write your own methods
}
public function loginAction()
{
    echo "har har mahadev";
//finally you can write your code that will rewrite the whole core method
//and you can call for your own methods, as you have full control over core controller
}
} 

等/config . xml:

<?xml version="1.0"?>
<config>
    <modules>
        <Inchoo_Coreextended>
            <version>0.2.0</version>
        </Inchoo_Coreextended>
    </modules>
    <frontend>
        <routers>
            <customer>
                <args>
                    <modules>
                        <Inchoo_Coreextended before="Mage_Customer_AccountController">
                            Inchoo_Coreextended_Frontend_Customer_AccountController
                        </Inchoo_Coreextended>
                    </modules>
                </args>
            </customer>
        </routers>
    </frontend>
</config>

当我试图登录时,它显示核心登录文件而不是我的模块登录,也不能显示任何错误和我的模块的值。所以请建议我,我能做些什么。

做这个更改,它将解决问题

  <config>
        <modules>
            <Inchoo_Coreextended>
                <active>true</active>
                <codepool>local</codepool>
            </Inchoo_Coreextended>
        </modules>
    </config>

<config>
    <modules>
        <Inchoo_Coreextended>
            <active>true</active>
            <codePool>local</codePool>
        </Inchoo_Coreextended>
    </modules>
</config>

codepool应该是codepool

首先,这个xml部分:

<Inchoo_Coreextended before="Mage_Customer_AccountController">
    Inchoo_Coreextended_Frontend_Customer_AccountController
</Inchoo_Coreextended>

应该是

<Inchoo_Coreextended before="Mage_Customer">Inchoo_Coreextended</Inchoo_Coreextended>

把它放在一行,因为Magento不修剪xml节点。

那么你的类应该放在

app/code/local/Inchoo/Coreextended/controllers/AccountController.php,应该命名为Inchoo_Coreextended_AccountController

检查下面的代码

<?xml version="1.0"?>
<config>
    <modules>
        <Inchoo_Coreextended>
            <version>0.2.0</version>
        </Inchoo_Coreextended>
    </modules>
    <frontend>
        <routers>
            <customer>
                <args>
                    <modules>
                        <Inchoo_Coreextended before="Mage_Customer">
                            Inchoo_Coreextended_AccountController
                        </Inchoo_Coreextended>
                    </modules>
                </args>
            </customer>
        </routers>
    </frontend>
</config>

和在你的模块中使目录结构为

Inchoo
  /Coreextended
   /controllers
    /AccountController.php

并在文件中将类设置为

class Inchoo_Coreextended_AccountController extends Mage_Customer_AccountController

希望有帮助!