【问题标题】:Simple controller with Magento 1.8.0Magento 1.8.0 的简单控制器
【发布时间】:2015-06-02 18:02:34
【问题描述】:

我是 Magento 世界的新手,我想创建像 here 描述的简单控制器。但是当我进入我的浏览器时,我得到了 404 错误。我试图在网上找到解决方案,但我没有。有人可以帮我吗?如果您需要一些和平的代码,请告诉我。谢谢!

附:模块处于活动状态,我检查了管理仪表板。

【问题讨论】:

  • 浏览 /var/www/html/magento/var/log/system.log 文件
  • 你能分享你的代码吗??
  • 分享你的代码以便理解?还有目录结构

标签: php magento routing


【解决方案1】:

目录结构应如下所示:

app/code/local/Magentotutorial/Helloworld/controllers/IndexController.php app/code/local/Magentotutorial/Helloworld/etc/config.xml

app/code/local/Magentotutorial/Helloworld/etc/config.xml):

<?xml version="1.0"?>
<config>    
    <modules>
        <Magentotutorial_Helloworld>
            <version>0.1.0</version>
        </Magentotutorial_Helloworld>
    </modules>
    <frontend>
        <routers>
            <helloworld>
                <use>standard</use>
                <args>
                    <module>Magentotutorial_Helloworld</module>
                    <frontName>helloworld</frontName>
                </args>
            </helloworld>
        </routers>  
    </frontend>
</config>

然后创建一个文件来激活模块(在路径app/etc/modules/Magentotutorial_Helloworld.xml):

<?xml version="1.0"?>
<config>
    <modules>
        <Magentotutorial_Helloworld>
            <active>true</active>
            <codePool>local</codePool>
        </Magentotutorial_Helloworld>
    </modules>
</config>

在

创建一个文件

app/code/local/Magentotutorial/Helloworld/controllers/IndexController.php

public function indexAction() {

        echo 'Hello Index!';

    }
}

在浏览器中浏览

 http://example.com/index.php/helloworld

就是这样。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-22
    • 2011-09-01
    相关资源
    最近更新 更多