Answer the question
In order to leave comments, you need to log in
Is it possible in Yii2 to get an array in an action from url parameters?
For example, I need to make a filter and organize the following url:
site.ru/users/view/user_id:56;date:day;status:1
Is it possible to get such an array somehow in the action:
[user_id]=>56
[date ]=>day
[status]=>1
Is this provided by Yii2 tools, or do I need to write my own (get $filter='user_id:56;date:day;status:1' and parse)?
Answer the question
In order to leave comments, you need to log in
Why can't POST be used? Cookies and write JSON there?
Can write with JSON syntax
site.ru/users/view/user/56?params={date: day, status: 1}
My advice to you: do not make such urls.
In the vast majority of cases, link auto-vivifiers will break off on a semicolon and the user will receive a broken url.
(clarification: when copy-pasting a url to a site that supports automatic replacement of "text that looks like url" with the actual link tag, the link exclusion regexp can go bad)
You can assign a CRoute successor as a route, and parse the string there, converting it to get parameters...
Why do you make /users/view/1 when you can try just /user1 for example? This will give you a more relevant level 1 page than level 3.
Spend a couple of hours on this.
Use readable urls. This is configurable in urlManager.
Generate url via Yii::app()->urlManager->createUrl.
If you really need "user_id: 56; date: day; status: 1" then you can write your own rule from regular expressions and add it to urlManager
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question