Created
October 26, 2014 03:11
-
-
Save jrbasso/37a6938b752b726b0a32 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home')); | |
Router::connect('/custom', array('controller' => 'wherever', 'action' => 'index')); | |
// ... Other routes | |
require CAKE . 'Config/routes.php'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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