class Router
外部管理代即将离任的url,传入请求uri的解析为参数设置,CakePHP可以派遣。
static Router::connect($route, $defaults = array(), $options = array())
Parameters:
$route (string) – A string describing the template of the route
$defaults (array) – An array describing the default route parameters. These parameters will be used by default and can supply routing parameters that are not dynamic.
$options (array) – An array matching the named elements in the route to regular expressions which that element should match. Also contains additional parameters such as which routed parameters should be shifted into the passed arguments, supplying patterns for routing parameters and supplying the name of a custom routing class.
路线是连接请求url对象的方式在您的应用程序。在他们的核心路线是一组或正则表达式用于匹配请求的目的地。
例子:
Router::connect('/:controller/:action/*');
第一个参数将被用作一个控制器名称,而第二个是用作动作名称。“/ *”的语法使得这个贪婪的在比赛,它将请求路由/文章/索引以及请求像/文章/编辑/ 1 / foo / bar。
Router::connect(
'/home-page',
array('controller' => 'pages', 'action' => 'display', 'home')
);
上面显示了使用线路参数的默认值。并提供路由参数静态路由。
Router::connect(
'/:lang/:controller/:action/:id',
array(),
array('id' => '[0-9]+', 'lang' => '[a-z]{3}')
);