AD7six.com

Plugins and Routes

5 September, 2006

Show comments

Routes are a great feature, but if you try using them with Plugins you might find that you start pulling your hair out. Fear not however, there's always a solution and it's usually not that difficult. If you use routes of the form below, you can map directly to a plugin's page:

$Route->connect(
    '/Something/*', 
    array(
        'controller' => 'PluginName', 
        'action' => 'ControllerName', 
        'Action'
    )
);
// Cake 1.2 syntax
Router::connect(
    '/Something/*', 
    array(
        'controller' => 'PluginName', 
        'action' => 'ControllerName', 
        'Action'
    )
);

Easy when you know how.

One word of warning though, the first parameter in this route has a default which is the controller action. This means that if you create route which expect parameters (as I did in the example) it will work with no parameters, but if any parameters are passed the first one will be understood to be the method name.

I suspect that at some point in the future, it'll be possible to directly specify the plugin in the route, but until then... ;)