我有以下routes.php配置
Router::connect('/:type/:slug;:id', array(
'controller' => 'content',
'action' => 'show',
'type' => null,
'slug' => null,
'id' => null,
),
array(
'type' => '(articles|releases|answers|videos)',
'slug' => '[a-zA-Z0-9\-]+',
'id' => '[0-9]+',
'pass' => array('type', 'slug', 'id'),
));
我正在尝试解析以下网址:
/answers/effective-language-therapy-for-people;368
路由器让我找到了正确的控制器&行动,但转储$this->params
告诉我,它无法正确识别$id
和$slug
Array
(
[type] => answers
[slug] => answers
[id] => effective-language-therapy-for-people
[named] => Array
(
)
[pass] => Array
(
[0] => answers
[1] => answers
[2] => effective-language-therapy-for-people
)
[controller] => content
[action] => show
[plugin] =>
[url] => Array
(
[ext] => html
[url] => answers/effective-language-therapy-for-people;368
)
[form] => Array
(
)
)
那么 - 是什么给出的?是我的正则表达式错误,方法缺少什么,或什么?有什么想法吗?
注意:我读过:
更新,已解决并正在运行的版本
Router::connect('/:type/:slug:splitter:id', array('controller' => 'content', 'action' => 'view',), array(
'type' => 'articles|releases|answers|videos',
'slug' => '[a-zA-Z0-9\-]+',
'splitter' => '[\;\-\|]+',
'id' => '[0-9]+',
));
答案 0 :(得分:7)
尝试:
Router::connect('/:type/:slug;:id', array(
'controller' => 'content',
'action' => 'show',
'type' => null,
'slug' => null,
'id' => null,
),
array(
'type' => 'articles|releases|answers|videos',
'slug' => '[a-zA-Z0-9\-]+',
'id' => '[0-9]+',
'pass' => array('type', 'slug', 'id'),
));
问题是括号()
中的类型,CakePHP不支持。