Yii CLinkPager & urlManager rules

泪湿孤枕 提交于 2019-12-12 01:21:50

问题


I have the following issue:

When I press a button in my pagination, CLinkPager generates the link as follows:

page/videos/445/?page=2
  1. What I need is something like this:

    page/videos/445/page/2

  2. Furthermore, I need something like:

    name/videos/2

where name is url of user_id = 445.

I've set some rules in urlManager but they don't quite do the job: For step 1:

'<controller:\w+>/<action:\w+>/<id:\d+>/<page:\d+>' => '<controller>/<action>',

Any help is appreciated. Thank you in advance!


回答1:


Here example for page/videos/445/page/2.This will help you understand:

//config
'rules'=>array(
            'page/videos/<number:\d+>/page/<pageId:\d+>' => '/site/test',
             ...

//...SiteController...
//url for call www.your_site.lh/page/videos/445/page/2
public function actionTest($number, $pageId)
{
    echo '<pre>';
    print_r($_GET);
    echo "$number<br/>";
    echo "$pageId<br/>";
    echo '</pre>';
    die();
}

URL Management

If you want to change generation links in pager you can override CLinkPager.



来源:https://stackoverflow.com/questions/30483938/yii-clinkpager-urlmanager-rules

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!