The site is on yii2, there is a task - to implement the replacement of parameters in the URL with "location = 2" by "location / moscow" and "tag = 7" by "tag / cs". That is, idi should be replaced by slug (in my case it is alias)

Replacement is needed only when parsing the URL, so that the old parameters (in the form of numbers) reach the controller, and the user sees a beautiful URL.

In the database there is a table fields, in which they lie in a separate column id and in a separate column alias (for example, id 2 and alias Moscow are also associated there). Added a new class to the rules:

'class' => 'frontend\models\GameRule' 

Class Content:

 <?php namespace frontend\models; use common\models\base\BaseFields; use yii\web\UrlRuleInterface; class GameRule implements UrlRuleInterface { public function createUrl($manager, $route, $params) { // создание url пока не нужно } public function parseRequest($manager, $request) { $pathInfo = $request->getPathInfo(); if (preg_match('%^(\w+)(?:/(\w+))(?:/(\w+))$%', $pathInfo, $matches)) { // вот здесь должно происходить сравнение } } public function getFields(){ $fieldData = BaseFields::find()->indexBy('alias')->all(); return $fieldData; } } 

The getFields method collects all data from a table and adds it to $ fieldData. As I understand it, now in the parseRequest method you need to compare what comes into the URL (with getPathInfo ()) with what is obtained from the database (in $ fieldData) and make a return. But here's how to compare and display, I can not figure out, with yii2 and frameworks for a couple of days.

    0