R
R
rommcr2014-12-25 14:24:08
Yii
rommcr, 2014-12-25 14:24:08

How to get an array of data from a Request using Yii2 methods according to certain rules?

To perform a specific operation, you need to get an array of parameters from a (get) request.
page: unsigned integer (default 1)
per_page: unsigned integer from the set (4,12,24,48), default - 4
skip: unsigned integer (default 1)
You can, of course, do everything manually using self-written functions type

$request = prepareArray('page,per_page,skip', true); // Получить именованный массив из request

$request['page'] = max(1, intval($request['page']));
$request['per_page'] = checkEnum($request['per_page'], '4,12,24,48');
$request['skip'] = abs(intval($request['skip']));

But maybe there are methods in Yii2 for this that I don't know about?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
rommcr, 2014-12-25
@rommcr

For myself, I solved the issue with the help of a model and custom validators.

A
Alexander Zelenin, 2014-12-25
@zelenin

No

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question