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;
[...]
}
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]);