我正在努力将我的项目从 CakePHP 1.2 升级到 1.3。在此过程中,插件的“神奇”路由似乎通过控制器名称(例如:“ForumsController”)与插件名称匹配(例如:“forums”)不再自动路由到插件 URL 的根目录(例如:“www.example.com/forums”指向插件“forums”,控制器“forums”,操作“index”)。

给出的错误信息如下:

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/index”,我也会得到同样的错误。

我是否需要明确设置我使用的每个插件的路由?这似乎破坏了我喜欢 CakePHP 的很多魔力。我只发现执行以下操作:

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

为每个插件设置 2 条路由似乎有点矫枉过正,不是吗?是否有更好的解决方案可以覆盖我的所有插件,或者至少减少我需要为每个插件设置的路由数量?

有帮助吗?

解决方案

我想,这个话题 配置和应用程序引导 涵盖:

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 (Cake 1.3 删除了魔法插件路由)。

其他提示

您不必在你的/应用/插件/为myplugin目录myplugin_app_controller.php。

只要创建包含以下文件:

<?php
class MypluginAppController extends AppController {

}
?>

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top