リチウムに一致するルートを作成したい
- / abc
- / abC
- / aBc
- 等々
これまでのところ、私はこのようなものを持っています:
Router::connect('/abc', array('Example::test'));
大文字と小文字を区別しないものに変更する可能性はありますか?
あなたの助けをありがとう、私はドキュメントで何かを見つけることができませんでした。
リチウムに一致するルートを作成したい
これまでのところ、私はこのようなものを持っています:
Router::connect('/abc', array('Example::test'));
大文字と小文字を区別しないものに変更する可能性はありますか?
あなたの助けをありがとう、私はドキュメントで何かを見つけることができませんでした。
オブジェクトのパターンパラメータをRoute
使用すると、大文字と小文字を区別しないパターンを定義できます(Nilsによる他の回答に記載されています)。
ルートで一般的に大文字と小文字を区別しないようにするためにRouter::formatters
、ルールを使用することもできることを指摘したいと思います。完璧ではありませんが、役立つ場合があります。Dispatcher
'/{:controller}/{:action}'
use lithium\action\Dispatcher;
use lithium\net\http\Router;
use lithium\util\Inflector;
/**
* The following Router and Dispatcher formatters keep our
* urls case-insensitive and nicely formatted using
* lowercase letters and dashes to separate camel cased
* controller and action names.
*
* Note that actions set in the routes file are also
* passed through the Dispatcher's rules. Therefore, we check if
* there is a dash in the action before lower casing it to make it
* case-insensitive. For most of the framework and php, case sensitivity
* is not an issue. However, the templates are derived from the action
* and controller names and case-sensitive file systems will cause
* differences in case to not find the correct template.
*
* This solution is not complete. It does not account for case sensitivity
* with controller names (because lithium's default handling doesn't touch
* the case of it and we're not overriding the default controller handling
* since it does at least camelize the controller). It also doesn't account
* for one word actions because they don't contain a dash. What probably needs
* happen is the Dispatcher needs a formatter callback specifically for
* translating urls.
*/
$slug = function($value) {
return strtolower(Inflector::slug($value));
};
Router::formatters(array(
'controller' => $slug,
'action' => $slug
));
Dispatcher::config(array('rules' => array(
'action' => array('action' => function($params) {
if (strpos($params['action'], '-')) {
$params['action'] = strtolower($params['action']);
}
return Inflector::camelize($params['action'], false);
})
)));
あなたはこのようにそれを行うことができるはずです:
Router::connect('/{:dummy:[aA][bB][cC]}', array('Example::test'));
編集:自分でRouteオブジェクトを作成することで、それを行うためのより良い方法もあります
Router::connect(new Route(array(
'pattern' => '@^/ab?$@i',
'params' => array('controller' => 'example', 'action' => 'test'),
'options' => array('compile' => false, 'wrap' => false)
)));
上記のパターンをブレーキアウトした場合'@^ / ab?$ @ i'
そして、あなたはここでより多くの情報を見つけることができます:http: //li3.me/docs/lithium/net/http/Route