2010-06-12 65 views
0

我正在將我的項目從CakePHP 1.2升級到1.3。在這個過程中,似乎插件的「神奇」路由通過其匹配插件名稱的控制器名稱(例如:「ForumsController」)(例如:「forums」)不再自動路由到插件URL的根目錄(例如:「www.example.com/forums」指向插件「論壇」,控制器「論壇」,行動「索引」)。爲CakePHP 1.3中的插件設置魔術路線?

給出錯誤消息是如下:

Error: ForumsController could not be found. 

Error: Create the class ForumsController below in file: app/controllers/forums_controller.php 

<?php 
class ForumsController extends AppController { 
    var $name = 'Forums'; 
} 
?> 

事實上,即使我導航到「www.example.com/forums/forums」或「www.example.com/forums/forums/索引「,我得到相同的確切的錯誤。

我是否需要爲每個使用的插件明確設置路由?這似乎破壞了我喜歡CakePHP的許多魔法。我只發現做了以下工作:

Router::connect('/forums/:action/*', array('plugin' => 'forums', 'controller' => 'forums')); 
Router::connect('/forums', array('plugin' => 'forums', 'controller' => 'forums', 'action' => 'index')); 

設置2路爲每一個插件似乎有點小題大做,不是嗎?是否有更好的解決方案可以覆蓋我所有的插件,或者至少減少我需要爲每個插件設置的路線數量?

回答

1

我想,這個話題Configuration-and-application-bootstrapping涵蓋:

App::build(array(
    'plugins' => array('/full/path/to/plugins/', '/next/full/path/to/plugins/') 
)); 

而且看看這張票:http://cakephp.lighthouseapp.com/projects/42648/tickets/750-plugin-route-problem-when-acl-and-auth-components-used#ticket-750-5(蛋糕1.3已經刪除魔法插件路由)。

+0

謝謝bancer,我應該提到我嘗試提供一個自定義插件數組到'App :: build()',但是這也沒有幫助。我使用的是AuthComponent,所以也許我遇到了與此票據描述相同的問題。我現在無法檢查,因爲我在工作,但感謝所報告的問題! – 2010-06-15 18:51:17

-1

您的/ app/plugins/myplugin目錄中沒有myplugin_app_controller.php。

只需創建一個包含下列文件:

<?php 
class MypluginAppController extends AppController { 

} 
?> 

,你將有你的插件的所有功能。 :)

+0

不,我肯定有該文件。雖然謝謝! – 2010-06-13 20:04:14