Skip to content

Instantly share code, notes, and snippets.

@jrbasso
Created October 26, 2014 03:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jrbasso/37a6938b752b726b0a32 to your computer and use it in GitHub Desktop.
Save jrbasso/37a6938b752b726b0a32 to your computer and use it in GitHub Desktop.
<?php
Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home'));
Router::connect('/custom', array('controller' => 'wherever', 'action' => 'index'));
// ... Other routes
require CAKE . 'Config/routes.php';
<?php
App::uses('ZumbaRoute', 'Routing/Route');
Router::defaultRouteClass('ZumbaRoute');
$routesFile = __DIR__ . '/routes.connect.php';
$routesHash = sha1_file($routesFile);
$cacheFile = TMP . '/routes-' . $routesHash . '.php';
if (file_exists($cacheFile)) {
include $cacheFile;
} else {
include $routesFile;
// Prepare for cache
foreach (Router::$routes as $i => $route) {
$route->compile();
}
$tmpCacheFile = TMP . '/routes-' . uniqid('tmp-', true) . '.php';
file_put_contents($tmpCacheFile, '<?php
Router::$initialized = true;
Router::$routes = ' . var_export(Router::$routes, true) . ';
');
rename($tmpCacheFile, $cacheFile);
}
Router::connectNamed(true);
<?php
App::uses('CakeRoute', 'Routing/Route');
/**
* Just a wrap of CakeRoute to support var_export
*/
class ZumbaRoute extends CakeRoute {
public static function __set_state($fields) {
$class = get_called_class();
$obj = new $class('');
foreach ($fields as $field => $value) {
$obj->$field = $value;
}
return $obj;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment