2013-12-19 120 views
2

希望有人可以幫助我一個測試Magento自定義模塊,我沒有運氣得到輸出。該模塊顯示在配置>高級,所以我認爲Helloworld_Mystuff.xml已正確完成,但我可能是錯的!我禁用了本地Magento管理員實例上的所有緩存。刷新緩存多次,登錄/退出管理,不同的瀏覽器。如果有問題,我使用apache在Mac上。Magento 1.8自定義模塊404

/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(); 
    } 
} 

/應用/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甚至沒有嘗試加載文件。

編輯: 我添加了一些附加的調試代碼在瓦瑞恩/路由器/ 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 

回答

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; 
} 

這將t當你試圖路由你的URL時,Magento正在尋找哪些類/文件,通常足以發現你的配置和/或類名和/或文件名中的錯字。在/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> 
+0

艾倫你好,我居然遇到了幾個SO的答案,你提出了這個我也試過:/app/code/core/Mage/Cms/controllers/IndexController.php和Mage_Cms_IndexController – james

+0

@james - 你確定這些是唯一的列出?至少Magento還會在前端搜索前在管理員中搜索控制器。 –

+0

是的,100%。當我使用調試代碼訪問管理面板時,我看到了所有文件列表,但當我轉到另一個前端頁面(例如產品)時,我只能看到一個:/ app/code/core/Mage/Catalog /controllers/ProductController.php/Mage_Catalog_ProductController – james

0

嘗試,這是一件非常愚蠢的,我的配置文件被錯誤地命名。艾倫的小費幫助我意識到路由器沒有被拿起,所以我從頭開始回來。

我打印出所有的路由器名稱Magento拿起,看到我的模塊不在那裏。

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

也不能工作:( – james

0

對不起球員使用這個

0

我有同樣的問題,在我的情況下,它是所有關於區分大小寫的話,我覺得你太:
試試這個

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

這裏是my question