我有以下routes.php文件配置CakePHP的路由器連接::()配置,自定義參數解析
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
(
)
)
那麼 - 什麼給?是我的正則表達式錯誤,方法錯過了什麼,或者是什麼?有任何想法嗎?
注:本人已閱讀:
- http://book.cakephp.org/view/948/Defining-Routes
- http://book.cakephp.org/view/949/Passing-parameters-to-action
UPDATE,解決和工作版本
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]+',
));
我不喜歡slug和數字之間的分號。 – Leo 2010-11-02 22:14:02
可以理解,對於我所關心的所有人來說,這可能是一個破折號或其他任何東西,但我正在減少此測試可能出現的問題的數量。 – zeroasterisk 2010-11-04 13:04:33