Skip to content

Instantly share code, notes, and snippets.

@bravo-kernel
Last active August 29, 2015 14:13
Show Gist options
  • Save bravo-kernel/5d0133bf6c61044f38bc to your computer and use it in GitHub Desktop.
Save bravo-kernel/5d0133bf6c61044f38bc to your computer and use it in GitHub Desktop.
Re-route DashboardsController routes to /dashboard and disable original/default route to /dashboards
<?php
/**
* CakePHP 3.x Routes configuration (/config/routes.php)
*/
use Cake\Core\Plugin;
use Cake\Routing\Router;
Router::scope('/', function ($routes) {
/**
* Enable RESTful routes for our controllers.
*/
$routes->extensions(['json']);
/**
* Connect /dashboard URLs to DashboardsController and disable /dashboards route.
*/
$routes->connect('/dashboards/*', ['controller' => null]);
$routes->connect('/dashboard', ['controller' => 'Dashboards', 'action' => 'index'], ['routeClass' => 'InflectedRoute']);
$routes->connect('/dashboard/:action/*', ['controller' => 'Dashboards'], ['routeClass' => 'InflectedRoute']);
/**
* Here, we are connecting '/' (base path) to a controller called 'Pages',
* its action called 'display', and we pass a param to select the view file
* to use (in this case, src/Template/Pages/home.ctp)...
*/
$routes->connect('/', ['controller' => 'Pages', 'action' => 'display', 'home']);
/**
* Connect a route for the index action of any controller.
* And a more general catch all route for any action.
* Using InflectedRoute so HtmlHelper::Link() will generate lowercase URL's
*/
$routes->connect('/:controller', ['action' => 'index'], ['routeClass' => 'InflectedRoute']);
$routes->connect('/:controller/:action/*', [], ['routeClass' => 'InflectedRoute']);
/**
* Load all plugin routes.
*/
Plugin::routes();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment