Pretty URL from GET method

How can I use pretty URL if I use the get method in my search form?

My AdController:




	public function actionShow()

	{

	

	 $searchModel = new search();

     $dataProvider = $searchModel->search(Yii::$app->request->queryParams);

	 $dataProvider->pagination->pageSize=12;

[...]

}

This is my URL: http://mywebsite.com/ad?search[cat]=1

I would like to replace it with this one: http://mywebsite.com/my_own_name

How can I do this?

It is too much generic using /my_own_name. So I suggest to use /ad/my_own_name.

In config.php urlManager component:




        'urlManager' => [

            'enablePrettyUrl' => true,

            'showScriptName' => false,

            'rules' => [

                

                // a standard rule mapping '/' to 'site/index' action

                'ad/<categoryName:\w+>' => 'ad/show',

            ],

        ], 



Then in the controller:




public function actionShow($categoryName)

{ 

     // Here you get $category object form categoryName

    

     $searchModel = new search();

     $dataProvider = $searchModel->search(Yii::$app->request->queryParams);

     $dataProvider->pagination->pageSize=12;

}



Finally you have only to change search() method passing category name instead category id; otherwise you can split search() method in searchQuery() that returns the query, then apply where() condition and finally get the active data provider from query, with:




$dataProvider = new \yii\data\ActiveDataProvider(['query' => $query]);