Skip to content

Instantly share code, notes, and snippets.

@nexeck
Forked from daGrevis/gist:1257357
Created October 2, 2011 12:38
Show Gist options
  • Save nexeck/1257411 to your computer and use it in GitHub Desktop.
Save nexeck/1257411 to your computer and use it in GitHub Desktop.
Route for mini-CMS
<?php
Route::set('cms', function($uri) {
$is_empty = empty($uri);
$does_exists = class_exists('Controller_' . $uri);
if ($is_empty || $does_exists) {
$default_route = Route::get('default');
$controller = Arr::get($default_route->defaults(), 'controller');
$action = Arr::get($default_route->defaults(), 'action');
if ($is_empty) {
return array(
'controller' => $controller,
'action' => $action,
);
} else {
return array(
'controller' => $uri,
'action' => $action,
);
}
}
/*if (preg_match('/(?P<controller>\w+)\/(?P<action>\w+)/', $uri, $matches)) {
return array(
'controller' => $matches['controller'],
'action' => $matches['action'],
);
}*/
if (preg_match('/^[a-zA-Z0-9_]+$/', $uri))
{
return array(
'controller' => 'cms',
'action' => 'page',
'slug' => $uri,
);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment