开发者

CakePHP - Route configuration

I am working on cakephp and totally a newbie to php/cakephp. Can you please tell me what is wrong with my route configuration here?

Router::connect(
 '/news/:q/:page',
 array('controller' => 'news', 
       'action' => 'onDemand',
       'mode'=>'news',
       'pag开发者_如何转开发e'=>1),
 array('pass'=>array('q','mode','page'),
       'page' => '[\d]+'));

When i access the page as /news/123 or /news/123/1, it tries to find for action '123' in news controller.

Basically all I want to do is that if user types /news/android , I want to capture 'android' to query and return the results. If there are too may results, need to support pagination i.e. url becomes /news/android/(2...n) .


You can just do this:

Router::connect('/news/*', array('controller' => 'news', 'action' => 'onDemand'));

Have your onDemand function declared as:

public function onDemand($subject, $page = null)

When a user requests /news/android or /news/android/2 cake will call onDemand('android') or onDemand('android', '2'), respectively.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜