Hello. Can you please tell me how to remove the id from the address bar? What would have been wrong, http://poll.ua/gonki/gonki-na-dronah/16 , and here it is http://poll.ua/gonki/gonki-na-dronah . In URLmanager in rules, I have the following:

 '<slug>/<slug1>/<poll_id:\d+>' => 'site/competition/', 

And I select articles via poll_id:

 public function actionCompetition($poll_id) { $comp = ACompetition::findOne($poll_id); return $this->render('competition', [ 'comp' => $comp, ]; } 
  • It is necessary to describe the method that will receive data on the CNC instead of findOne - fedornabilkin

1 answer 1

I implemented it like this:

Given that we have a table with Category categories, each category has an alias field (in your version it is a category with alias = 'gonki' ), and in the ACompetition table we only have a link to the category by id.

Rule in UrlManager:

 '<category:[\w\-]+>/<alias:[\w\-]+>' => 'site/competition/' 

Action:

 public function actionCompetition($category, $alias) { $category = Category::findOne(['alias' => $category]); $comp = ACompetition::findOne(['category_id' => $category->id, 'alias' => $alias]); return $this->render('competition', [ 'comp' => $comp, ]; }