如果您在 URL 中没有任何关于页面、项目和类别之间的约定。我会选择一个非常通用的路由器。
Router::connect('/{:category}/{:page}/{:item}', 'Pages::any');
Router::connect('/{:category}/{:page}', array('Pages::any', 'item' => null));
Router::connect('/{:category}', array('Pages::any', 'page' => null, 'item' => null));
And in Pages::any()
寻找正确的东西。就是它category
a page
毕竟(示例 4)?就是它page
an item
(示例1)?
or
您将 URL 存储在某处(例如数据库中的映射表)并使用pattern
的版本锂路线 http://lithify.me/docs/lithium/net/http/Route.
Router::connect(new Route(array(
'pattern' => '@^/(?<path>.+)$@',
'params' => array('controller' => 'pages', 'action' => 'any'),
'keys' => array('path' => 'path'),
// extra stuff, if the path is `tata`, it skips this route and uses
// any of the following ones that matches.
'handler' => function($request) {
if ($request->params['path'] == 'tata') {
return false;
} else {
return $request;
}
}
)));
从那时起,您将获得完整的 URL。