Search code examples
pluginsroutescakephp-1.3prefixcakephp-1.2

Prefix routing and plugins in CAKEPHP 1.2/1.3


Does anybody have examples of setting up the routes.php table when using plugins and prefix routing in CakePHP

e.g.

A shops controller, using the manage prefix to access certain management functions for the seller.

So /manage/shops/edit maps to manage_edit in shops_controller.php

and then placing this in /plugins/shops


Solution

  • In your core.php there is a configuration value called: Routing.prefixes you need to set the manage prefix there:

    Configure::write('Routing.prefixes', array('admin', 'manage'));

    Now all calls to URLs like /manage/controllerName/actionName will go to: controllerName::manage_actionName

    and all calls to URLs like /admin/controllerName/actionName will go to: controllerName::admin_actionName

    For plugin routing in the routes.php file:

    Router::connect('/shops/edit', array('plugin' => 'pluginName', 'controller' => 'shops', 'action' => 'edit'));
    

    This is all that is needed.