Answer the question
In order to leave comments, you need to log in
Yii2 how to specify a default value when getting a value from a Get request?
For example, there is a url index.html?LangSearch[name]=ru (this is in the admin interface)
if you take it like this
Yii::$app->request->getQueryParam("LangSearch[name]", 'en'),
then it does not work, that is, it will always be "en" (well, this is clear to me from the code of the method itself). If we take
$langName = Yii::$app->request->getQueryParam("LangSearch"),
and then $langName = isset($langName["name"])?$langName["name"]:"en" ;
it gets too long. Is there a way to take this variable in one method with a default value without building your bike?
I will add for a more complete understanding, the url can be like this index.html?LangSearch[name]=ru&LangSearch[locale]=ru-Ru&LangSearch[default]=0
Answer the question
In order to leave comments, you need to log in
so www.yiiframework.com/doc-2.0/guide-runtime-request
...
$lang = Yii::$app->request->get('LangSearch', 'en');
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question