Setting up magic routes for plugins in CakePHP 1.3?
I'm working on upgrading my project from CakePHP 1.2 to 1.3. In the process, it seems that the "magic" routing for plugins by which a controller name (e.g.: "ForumsController") matching the plugin name (e.g.: "forums") no longer automatically routes to the root of the plugin URL (e.g.: "www.example.com/forums" pointing to plugin "forums", controller "forums", action "index").
The error message given is as follows:
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';
}
?>
In fact, even if I navigate to "www.example.com/forums/forums" or "www.example.com/forums/forums/index", I get the same exact error.
Do I need to explicitly set up routes to every single plugin I use? This seems to destroy a lot of the magic I like about CakePHP. I've only found that doing the following works:
Router::connect('/forums/:action/*', array('plugin' => 'forums', 'controller' => 'forums'));
Router::connect('/forums', array('plugin' => 'forums', 'controller' => 'forums', 'action' => 'index'));
Setting up 2 routes for every single plugin seems like overkill, does it not? Is there a better solution that will cover all my plugins, or at least reduce the number of routes I need to set up for each plugin?
Asked by mhuggins, on 12/6/10
2 Answers
Seems odd that the /forums/forums route is not working. These are routes that are supported and well tested. Perhaps a App wasn't able to find the plugin? I would take a look at the routes stored inside Router and see which routes are connected. That should give you some insight onto why the default plugin routes are not working.
Answered by markstoryon 13/6/10
Another interesting note...on cake/router.php on line 571, if I tell the call to App::objects to not utilize the cache (i.e.: change App::objects('plugin')` to `App::objects('plugin', null, false), then suddenly the routes seem to work. When it's using the cache, I can see that CakePHP is incorrectly caching to cake_core_object_map an empty array:
1276460129
a:1:{s:6:"plugin";a:0:{}}
So for some reason, it seems that the Router object is correctly loading finding the plugins when not reading from cache, but then it is not caching the details about them properly when it is dealing with the cache. It appears to be a bug somewhere in the core from my end. I'll keep digging and see if I can find anything more, but I'd be surprised if no one else has encountered this issue yet.
mhuggins - on 13/6/10
You can have a default controller with the name of your plugin. If you do that, you can access its index action via /[plugin]. Unlike 1.2 only the index action route comes built in. Other shortcuts that were accessible in 1.2 will need to have routes made for them. This was done to fix a number of workarounds inside CakePHP
source: http://book.cakephp.org/view/1118/Plugin-Tips
still looking for an alternative or something ...
Answered by martuon 26/6/10
Your Answer
You can use Creole Wiki Syntax to format your text.
Tagged with
Rating
0
Viewed
285 times
Last Activity
on 26/6/10