V
V
Vitalij Rudyuk2014-11-06 12:52:53
Yii
Vitalij Rudyuk, 2014-11-06 12:52:53

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

2 answer(s)
I
Ivan Gontarenko, 2014-11-06
@Faradey

so www.yiiframework.com/doc-2.0/guide-runtime-request
...

$lang = Yii::$app->request->get('LangSearch', 'en');

S
Sergey, 2014-11-06
Protko @Fesor

And in what a problem it is normal to form querystring? Type
/search?locale=en&q=test

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question