Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CakePHP - Loading routes files from a plugin

Can someone point to me how this is done? I want to define plugin specific routes in a config file within the plugin's folder itself.

At the moment I am simply defining routes that are for plugins in my main routes.php file. Which can obviously get very long. So I want to refactor it out to a separate config file and place it in the plugin's folder.

But I saw that there is a code that actually loads plugin-specific routes automatically but I cannot find any documentation on this. In "config/routes.php", there is a line that says

/**
 * Load all plugin routes.  See the CakePlugin documentation on 
 * how to customize the loading of plugin routes.
 */
CakePlugin::routes();

Searching through plugin routing here is on a totally different subject. And the plugin documentation mentions nothing about this.

like image 941
MechaStorm Avatar asked Aug 28 '12 17:08

MechaStorm


1 Answers

Check out the documentation in this section: Plugin Configuration.

First, add your routes to app/Plugin/YourPlugin/Config/routes.php

And do this in app/Config/bootstrap.php:

<?php
CakePlugin::loadAll(array(
    'Blog' => array('routes' => true),
    'ContactManager' => array('bootstrap' => true),
    'WebmasterTools' => array('bootstrap' => true, 'routes' => true),
));

And it will load all your available plugins, but add the extras you list in the array parameter. If you want to load routes for all your available plugins, do this in app/Config/bootstrap.php:

<?php
CakePlugin::loadAll(array(
    array('bootstrap' => true)
));

Good luck!

like image 51
MorganGalpin Avatar answered Sep 26 '22 21:09

MorganGalpin