【发布时间】:2014-02-18 11:25:23
【问题描述】:
我想做的是自动匹配 URI,并为它们分配正确的描述。假设我有以下 URI:
test
something/action
controller/test
controller/another
controller/action/something
action
action/test
controller/another/somethingelse
它们确实是随机的,但现在我想使用以下数组(数组,因为我认为这将是最好的解决方案)来匹配它们:
$config = array(
'test' => 'The description of test',
'something/action' => 'Some action description',
'controller/another' => 'Another description',
'controller/action/*' => 'This should match the `controller/action/blah` and everything similar like: `controller/action/something` and give this description'
'action' => 'Action description',
'action/*' => 'As the 2nd above, this should match the `action/test` itself, and similar like `action/anothertest` URI
);
这很容易,如果没有星号...(只需 $config[$uri] 以匹配描述)但我也想匹配星号...所以如果有像 controller/another/name 这样的控制器和我会使用像controller/another/* 这样的配置,它会匹配这个数组键的描述。
有人知道怎么做吗?我基本上需要想法,但欢迎任何其他答案!
【问题讨论】: