Matt Huggins
Matt Huggins

Reputation: 83279

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?

Upvotes: 0

Views: 2798

Answers (2)

bancer
bancer

Reputation: 7525

I guess, that topic Configuration-and-application-bootstrapping covers that:

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

Also take a look at this ticket: http://cakephp.lighthouseapp.com/projects/42648/tickets/750-plugin-route-problem-when-acl-and-auth-components-used#ticket-750-5 (Cake 1.3 had removed magic plugin routes).

Upvotes: 1

Nik Chankov
Nik Chankov

Reputation: 6047

You don't have myplugin_app_controller.php in your /app/plugins/myplugin directory.

Just create a file containing following:

<?php
class MypluginAppController extends AppController {

}
?>

And you will have all your plugin's features. :)

Upvotes: -1

Related Questions