N
N
nepster-web2014-03-14 03:09:27
Yii
nepster-web, 2014-03-14 03:09:27

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

5 answer(s)
M
Mikhail Bazhenov, 2014-03-17
@nepster-web

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}

Y
Yuri Morozov, 2014-03-14
@metamorph

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)

S
Sergey, 2014-03-14
Protko @Fesor

You can assign a CRoute successor as a route, and parse the string there, converting it to get parameters...

L
lxfr, 2014-03-14
@lxfr

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.

A
Alexey Volegov, 2014-10-16
@EagleMoor

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 question

Ask a Question

731 491 924 answers to any question