T
T
teodor7teodor72016-06-09 09:44:05
Yii
teodor7teodor7, 2016-06-09 09:44:05

How to make yii2 REST fetch start, limit?

Good afternoon, how can I make a selection in Yii2, the client passes start and limit.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
teodor7teodor7, 2016-06-09
@teodor7teodor7

public function actionIndex() {
    
    $query = Users::find();
    $start = \Yii::$app->request->get('start');
    $limit = \Yii::$app->request->get('length');


    $pagination = new Pagination([
      'totalCount' => $query->count(),
    ]);

    $users['data'] = $query->offset($start)
      ->limit($limit)
      ->all();

    $users['recordsTotal'] = $pagination->totalCount;
    $users['recordsFiltered'] = $pagination->totalCount;

  return $users; 
  }

It turned out at the exit, please.

M
Maxim Fedorov, 2016-06-09
@qonand

sample where? in ActiveQuery?
if yes then
Model::find()->offset($start)->limit($limit)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question