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

时间:2014-07-09 06:54:40

标签: php magento module controller

我正在扩展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
}
} 

和etc / 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>

当我尝试登录时显示核心登录文件而不是我的模块登录,并且也无法显示任何错误和我的模块中的值。 所以请建议我,我该怎么办。

3 个答案:

答案 0 :(得分:1)

进行此更改,它将解决问题

  <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

答案 1 :(得分:0)

首先,这个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

其余接缝没问题。

答案 2 :(得分:0)

检查以下代码

<?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
希望它有所帮助!