public
Created — forked from nateabele/routes.php

  • Download Gist
routes.php
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
<?php
/**
* Continuation routing examples. Handles URLs in the following forms:
*
* /posts
* /en/posts
* /admin/posts
* /admin/en/posts
* /admin/en/posts.json
* /admin/en/posts/4ef16ccc7f8b9aa331000064.json
* /admin/posts/4ef16ccc7f8b9aa331000064.json
* /en/posts/edit/4ef16ccc7f8b9aa331000064
* /posts/4ef16ccc7f8b9aa331000064
*
* ...as well as many, many other permutations.
*/
 
use lithium\net\http\Router;
use lithium\core\Environment;
use lithium\action\Dispatcher;
 
/**
* Add a Dispatcher rule to rewrite actions with prefixes whenever the `admin` flag is encountered
* in parameters returned from routing.
*/
Dispatcher::config(array('rules' => array(
'admin' => array('action' => 'admin_{:action}')
)));
 
/**
* Continuation route for admin requests. Instead of dispatching to `{Controller}::{action}()`,
* matching routes will dispatch to `{Controller}::admin_{action}()`, per the dispatch rules
* defined above.
*/
Router::connect('/admin/{:args}', array('admin' => true), array(
'continue' => true, 'persist' => array('controller', 'admin')
));
 
/**
* Continuation routes for locale detection. Make sure to include `bootstrap/g11n.php`
* and configure your locales.
*/
Router::connect(
'/{:locale:' . join('|', array_keys(Environment::get('locales'))) . '}/{:args}',
array(),
array('continue' => true)
);
 
/**
* Static pages.
*/
Router::connect('/', 'Pages::view');
Router::connect('/pages/{:args}', 'Pages::view');
 
/**
* Handling API output formats.
*/
Router::connect('/{:args}.{:type:json|rss|xml}', array(), array('continue' => true));
 
/**
* MongoDB document routes.
*/
Router::connect('/{:controller}/{:id:[0-9a-f]{24}}', array('action' => 'view'));
Router::connect('/{:controller}/{:action}/{:id:[0-9a-f]{24}}');
 
/**
* Default route.
*/
Router::connect('/{:controller}/{:action}/{:args}');
 
?>

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.