2012-12-03 62 views
1

從指令的Alan's blog,我在config.xml中添加路由器:Magento管理控制器提供了404

<?xml version="1.0"?> 
<config> 
    <modules> 
     <Clean_Integration> 
      <version>1.0.0</version> 
     </Clean_Integration> 
    </modules> 
    <admin> 
     <routers> 
      <wellnesscoach_app_redirect> 
       <use>admin</use> 
       <args> 
        <module>Clean_Integration</module> 
        <frontName>appsync</frontName> 
       </args> 
      </wellnesscoach_app_redirect> 
     </routers> 
    </admin> 
</config> 

然後我在這裏app/code/local/Clean/Integration/Controllers/IndexController.php定義我的控制器:

<?php 

die('checkpoint1'); 

class Clean_Integration_IndexController extends Mage_Adminhtml_Controller_Action { 

    public function indexAction() { 
     $this->_redirectUrl('/appointments/sync/backend/'); 
     die('checkpoint2'); 
    } 
} 

當我試圖打開這個網址,它前往前端並拋出一個404.

什麼是導致magento不拿起這個管理路由器?

+0

什麼是整合?它看起來像你重定向到一個單獨的應用程序? – benmarks

+0

@benmarks無法在頂層菜單中添加外部鏈接,因此通過管理控制器重定向。 – Ashfame

+0

哦,我明白了。 *是*限制。這**可以**只用* config.xml *和* system.xml *我認爲。 – benmarks

回答

3
<?xml version="1.0"?> 
<config> 
    <modules> 
     <Clean_Integration> 
      <version>1.0.0</version> 
     </Clean_Integration> 
    </modules> 
    <admin> 
    <routers> 
     <integration> 
      <use>admin</use> 
      <args> 
       <module>Clean_Integration</module> 
       <frontName>appsync</frontName> 
      </args> 
     </integration> 
    </routers> 
    </admin> 

應該爲小寫controllers

應用程序/代碼/本地/清潔/集成/控制器/ IndexController.php

您可能還希望把這個Adminhtml文件夾,這樣你不運行如果您想要添加frontendadmin控制器,將來可能會出現問題。

應用程序/代碼/本地/清潔/集成/控制器/ Adminhtml/IndexController.php

+0

採取這種方法時,請記住您的模塊的所有URL都需要子文件夾,例如'site.com/appsync/adminhtml_controller/action' – benmarks

+0

謝謝! 'c'而不是'C'是這裏的錯誤,但我不明白你想告訴我的邊緣情況。我沒有看到你在上面發佈的XML中的任何區別。 – Ashfame

+0

如果這不是一個錯誤,而是更好的實踐(在我看來),由於magento創建一個大XML的方式,如果你有兩個具有相同標記名的模塊,那麼功能就停止工作,所以我總是保留XML標記名稱與自定義模塊相同以防止衝突。我花了4個多小時才弄明白這一點 –

1

我發現你犯的一個錯誤是把控制器放在名爲'Controllers'的文件夾中,而不是'controllers'(大小寫錯誤)。

+0

是的,就是這樣。謝謝! – Ashfame

0

供將來參考別人這個問題:

如果控制器不使用標準名稱的IndexController.php,您仍需要使用...Controller慣例命名文件名稱名稱和類別名稱。

所以,如果你的控制器住在Adminhtml文件夾,命名爲ExtensionController.php和內My_Module_Adminhtml_ExtensionController extends ...

感謝去this excellent article命名類。 HTH。

相關問題