Magento 1.8自定义模块404

时间:2013-12-19 06:37:21

标签: magento

希望有人可以帮我一个测试Magento定制模块,我没有运气输出。该模块显示在Configuration>中高级,所以我假设Helloworld_Mystuff.xml已正确完成,但我可能错了!我在我的本地Magento管理实例上禁用了所有缓存。刷新缓存多次,登录/退出管理员,浏览器不同。如果重要的话,我在使用apache的Mac上。

/etc/modules/Helloworld_Mystuff.xml(不包括xml行)

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

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

class Helloworld_Mystuff_IndexController extends Mage_Core_Controller_Front_Action{
  public function indexAction(){
    echo "test";
    //$this->loadLayout()->renderLayout();
  }
}

/app/code/local/Helloworld/Mystuff/etc/config.xml

<config> 
    <modules>
        <Helloworld_Mystuff>
            <version>0.0.1</version>
        </Helloworld_Mystuff>
    </modules>
     <frontend>
                <routers>
                    <helloworld>
                        <use>standard</use>
                        <args>
                              <module>Helloworld_Mystuff</module>
                              <frontName>helloworld</frontName>
                        </args>
                    </helloworld>
                </routers>
     </frontend>
</config>

试着做 - / helloworld / index
- / helloworld / index / index

导致404错误。

我尝试在/varien/Router/Standard.php中添加一些调试代码,以便在调用我的测试URL时查看它正在寻找的类,并且它正在寻找Mage_Cms_IndexController。因此,我的自定义模块没有加载,因为Magento甚至没有尝试加载文件。

编辑: 我在函数中的Varien / Router / Standard.php中添加了一些额外的调试代码:

public function match(Zend_Controller_Request_Http $request)
{
//checking before even try to find out that current module
//should use this router
if (!$this->_beforeModuleMatch()) {
    return false;
}

$this->fetchDefault();

$front = $this->getFront();
$path = trim($request->getPathInfo(), '/');

if ($path) {
    $p = explode('/', $path);
} else {
    $p = explode('/', $this->_getDefaultPath());
}
echo "<br />front = " . ($front);
echo "<br />path = " . ($path);
echo "<br />request->getModuleName = ".$request->getModuleName();

输出

front =
path = helloworld/index
request->getModuleName =
front =
path = helloworld/index
request->getModuleName =
front =
path = helloworld/index
request->getModuleName = cms
front =
path = helloworld/index
request->getModuleName = cms 

4 个答案:

答案 0 :(得分:3)

使用以下方法(var_dump s)

删除一些调试代码
#File: app/code/core/Mage/Core/Controller/Varien/Router/Standard.php
protected function _validateControllerClassName($realModule, $controller)
{
    $controllerFileName = $this->getControllerFileName($realModule, $controller);
    var_dump($controllerFileName);
    if (!$this->validateControllerFileName($controllerFileName)) {
        return false;
    }

    $controllerClassName = $this->getControllerClassName($realModule, $controller);
    var_dump($controllerClassName);
    if (!$controllerClassName) {
        return false;
    }

    // include controller file if needed
    if (!$this->_includeControllerClass($controllerFileName, $controllerClassName)) {
        return false;
    }

    return $controllerClassName;
}

这将告诉您Magento在尝试路由您的URL时正在寻找哪些类/文件,并且通常足以找出您的配置和/或类名和/或文件名中的拼写错误。

答案 1 :(得分:0)

尝试在/app/code/local/Helloworld/Mystuff/etc/config.xml中使用它

<config> 
  <modules>
    <Helloworld_Mystuff>
      <version>0.0.1</version>
    </Helloworld_Mystuff>
  </modules>
  <frontend>
    <routers>
      <mystuff>
        <use>standard</use>
        <args>
          <module>Helloworld_Mystuff</module>
          <frontName>helloworld</frontName>
        </args>
      </mystuff>
    </routers>
  </frontend>
</config>

答案 2 :(得分:0)

对不起伙计们,这真的很蠢,我的配置文件命名不正确。艾伦的小费让我意识到路由器没有被拿起,所以我从头开始。

我打印出Magento拿起的所有路由器名称,看到我的模块不在那里。

foreach ($routers as $routerName=>$routerConfig) {
echo $routerName;

答案 3 :(得分:0)

我有同样的问题,在我的情况下,所有关于区分大小写的单词,我认为你也是如此:
试试这个

<frontend>
     <routers>
           <Mystuff>
                <use>standard</use>
                <args>
                     <module>Helloworld_Mystuff</module>
                     <frontName>helloworld</frontName>
                </args>
           </Mystuff>
     </routers>
</frontend>

这里是my question

相关问题