Yii2 How to remove site/index and page parameter from url

前端 未结 1 539
萌比男神i
萌比男神i 2021-01-25 19:09

I am using pagination on default page,i.e, on site/index in yii2. So the URL generated by linker for paginations looks like this

domain.com/site/index?page=1


        
相关标签:
1条回答
  • 2021-01-25 19:36

    I got this working on my local machine using the following component configuration:

    'urlManager' => [
        'class' => 'yii\web\UrlManager',
        'enablePrettyUrl' => true,
        'showScriptName' => false,
        'baseUrl' => 'http://example.dev',
        'rules' => [
            [
                'pattern' => '<page:\d+>',
                'route' => 'site/index'
            ]
        ],
    ]
    

    and SiteController:

    public function actionIndex($page=NULL)
    {
        var_dump($page);
        exit;
    }
    
    0 讨论(0)
提交回复
热议问题