Answer the question
In order to leave comments, you need to log in
How to pass url to Yii2 controller?
Let's say they access the site page. The domain.com/products/samsung-548z
request is passed to the show method in the products controller, obviously the model should get inside the method. samsung-548z but how to transfer it there?
public function actionShow($model)
{
var_dump($model);
}
Answer the question
In order to leave comments, you need to log in
In general, $model = Yii::$app->request->get();
what you did depends on what is written in your rules
You need to write a rule in the urlManager in the main.php config (or web.php for basic)'products/<model:[\w\-]+>' => 'products/show',
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question