希望有人可以幫助我一個測試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
艾倫你好,我居然遇到了幾個SO的答案,你提出了這個我也試過:/app/code/core/Mage/Cms/controllers/IndexController.php和Mage_Cms_IndexController – james
@james - 你確定這些是唯一的列出?至少Magento還會在前端搜索前在管理員中搜索控制器。 –
是的,100%。當我使用調試代碼訪問管理面板時,我看到了所有文件列表,但當我轉到另一個前端頁面(例如產品)時,我只能看到一個:/ app/code/core/Mage/Catalog /controllers/ProductController.php/Mage_Catalog_ProductController – james