【问题标题】:Magento Module IndexController - IndexAction function 404'sMagento 模块 IndexController - IndexAction 功能 404 的
【发布时间】:2011-07-13 19:52:22
【问题描述】:

删除 IndexAction 周围的类会导致服务器错误,因此我知道代码在此时按预期运行。

class Foo_Bar_IndexController extends Mage_Core_Controller_Front_Action{
    public function indexAction(){
        echo "<h1>Echo from indexcontroller.</h1>";
    }
}

理想情况下,echo 将被加载模板文件替换,但过去 2 天我一直卡在 404ing 上,只是想摆脱它。

我已经阅读了大约十几个教程,然后完成了 4 个教程,但是每次都会弹出这个问题。 有谁知道是什么原因造成的?

编辑—— 对不起,为了简洁。我不确定我应该将页面扩展多少。

@ Alan Storm——我在这里找到了你的教程。 http://alanstorm.com/magento_controller_hello_world(非常详细,非常有助于理解所有 xml 标签的作用)。这是该教程的副本,其中 Foo 替换了 Alanstormdotcom,Bar 替换了 Helloworld。即使是复制/粘贴,我也会得到相同的 404。

这是我当前的配置文件: PATH:app/code/local/Foo/Bar/etc/config.xml(编辑:更正路径)

<config>
<modules>
    <Foo_Bar>
        <version>0.1.0</version>
    </Foo_Bar>
</modules>
<frontend>
    <routers>
        <bar>
            <use>standard</use>
            <args>
                <module>Foo_Bar</module>
                <frontName>bar</frontName>
            </args>
        </bar>
    </routers>  
</frontend>
</config>

编辑--- 最后剩下的文件 路径:app/etc/modules/Foo_Bar.xml

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

【问题讨论】:

  • 你能把 Bar 模块的 magento 安装和模块的 config.xml 文件的相对路径贴出来吗?
  • 如果您已阅读教程并认为有人可以用这些小信息回答您的问题,那么您还没有阅读教程。

标签: php model-view-controller magento module controller


【解决方案1】:

我认为您缺少在 URL 中添加 store_code(我遇到了同样的问题),可能您已经从管理员启用了商店代码,换句话说,商店代码(例如:en、nl 等)正在 URL 中添加。

例如:

www.example.com/zh/aaa.html

如果是这样,那么请以这种方式访问​​您的控制器和操作:

www.example.com/store_code/front_name/controller/action

例如:

www.example.com/zh/bar/index/index

【讨论】:

  • 我刚刚发现了我的错误,感谢您的回答+1
【解决方案2】:

你的路径不正确:

app/etc/modules/Foo/Bar/etc/config.xml

您应该将模块的定义文件Foo_Bar.xml 放在app/etc/modules 中,并将模块的代码放在app/code/local 中:

app/code/local/Foo/Bar/etc/config.xml
app/code/local/Foo/Bar/controllers/IndexController.php

编辑:为了访问您的控制器,您应该访问此网址:

www.example.com/magento-instance/bar/index

遵循这个模式:

{magento_root}/{magento_module}/{magento_controller}/{magento_action}

【讨论】:

  • 对不起。它在您列出的路径中。我刚才抄错了。
  • 您使用哪个 URL/URI 来访问控制器?
  • example.com/magento-instance/bar
  • 默认应用action的索引。但在这种情况下,“索引”是控制器名称。
  • 据我所知,默认情况下应该应用索引,例如。 www.yourdomain.com/magento-instance/bar/index == www.yourdomain.com/magento-instance/bar 我都试过了,但我都得到了 404。
【解决方案3】:

如果其他答案对您没有帮助,您可能想尝试以下路径模式:

     www.example.com/index.php/frontName/controllerName/actionName

我不明白他们为什么不为这种网址创建重写规则。

无论如何,上面的模式应该在大多数情况下都有效。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-05-26
    • 1970-01-01
    • 1970-01-01
    • 2013-12-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多