How take get parameters for sorting items by category?

In my database I have items with categry field (from 1… to inf)

Controller action:


public function actionIndex()

    {

        $searchModel = new AdsSearch();

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


        return $this->render('index', [

            'searchModel' => $searchModel,

            'dataProvider' => $dataProvider,

        ]);

    }

View:


<?= ListView::widget([

    'dataProvider' => $dataProvider,

    'itemOptions' => ['class' => 'item'],

    'itemView' => '_item_view',,

]) ?>

I have enabled prettyUrl


'urlManager' => [

            'enablePrettyUrl' => true,

            'showScriptName' => false,

        ],

And .htaccess in frontend/web/


RewriteEngine on

 

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule . index.php

  1. How can I show items that were find only by category?

Now mysite.com/items show all items with mixed categories

I want to make mysite.com/items/cat/1 or mysite.com/items/1 with category = 1

  1. Is there any article how to make mysite.com/items/category-name-url instead number? I store category names in $app->params

Next item page with id=5 will be mysite.com/items/category-name-url/5