Answer the question
In order to leave comments, you need to log in
How to get GET parameters in Route Yii?
I want to get parameters in the GET controller in the standard way:
Yii::$app->request->get('aID', '');
Yii::$app->request->get('aTitle', '');
'article/description/<aID:\d+>/<aTitle>' => 'article/description'
'article/description/<aID:\d+>/<aTitle>' => 'article/description'
Answer the question
In order to leave comments, you need to log in
You need to distinguish between path and query parameters.
For example:
Here aID=323&aTitle=teaser+of+this+article
it is the query parameters.
Accordingly, they do not need to be specified in the route:
They are implicitly passed to the action.
In this case, all query parameters will be required. To change this, you need to set the default values:
public function actionDescription($aID, $aTitle = null, $something = 'default', $else = 1) {}
Create URLs with Url::to, and always specify the same order of parameters, and everything will work correctly. then you can get by with just two rules in the UrlManager.
Or create your own URL parsing rules and be able to process them even if the order is arbitrary. A rough example can be found here https://yiiframework.com.ua/ru/doc/guide/2/runtime...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question