I tried to create my own rule:

namespace frontend\components; class SerialsUrlRule extends Object implements UrlRuleInterface { public function createUrl($manager, $route, $params) { if ($route === 'serial/category/oneserial') { if (isset($params['id'])) return 'serials/' . $params['id']; } elseif ($route === 'serial/category/list') { if (isset($params['slug'])) return 'serials/' . $params['slug']; } return false; // данное правило не применимо } public function parseRequest($manager, $request) { $pathInfo = $request->getPathInfo(); if (preg_match('%^(\w+)(/(\w+))?$%', $pathInfo, $matches)) { $path = $matches[0]; if ($path == 'serial/category/oneserial') { $exists = Serial::find() ->where([ 'slug_serial' => $matches[1] ])->exists(); if ($exists) return ['serial/category/oneserial', 'id' => $matches[1]]; } if ($path == 'serial/category/list') { $exists = Category::find() ->where([ 'slug_category' => $matches[1] ])->exists(); if($exists) return ['serial/category/list','slug'=>$matches[1]]; } } return false; } } 

In the config / main.php connect so

 [ 'class' => 'frontend\components\SerialsUrlRule', ], 

I would like the link <?= Yii::$app->urlManager->createUrl(['/serial/category/oneserial','id'=>$model->slug_serial])?> pars so serials / serial- nazvanie, and it is so parsed, but at the same time, but an error 404 occurs.

I would also like Yii::$app->urlManager->createUrl(['/serial/category/list','slug'=>$ct->slug_category]) parse this link serials / nazvanie-category the same thing happens Parsing gives 404 error

Action:

 public function actionList($slug=null){ $model = Serial::findOne(['slug_serial'=>$id]); //... } public function actionList($slug=null){ if ($slug == null) { $categoryThe = Category::find()->all(); } else { $categoryThe = Category::findOne(['slug_category' => $slug]); } //..., использую avtivedataprovider } 
  • The third question on these series of your fruit and do not want to develop a dialogue. Why all this? - zabachok
  • @zabachok serials some principles of implementation are different - Sergalas
  • Please put punctuation marks, otherwise it is very difficult to understand these small groups of words. - zabachok
  • @zabachok let's finish our skirmish in it makes no sense, thanks in advance. - Sergalas

0