Yii CLinkPager & urlManager rules

2019-09-10 10:15发布

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条回答
孤傲高冷的网名
2楼-- · 2019-09-10 10:51

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.

查看更多
登录 后发表回答