Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function actionGetData()
- {
- $request = Yii::$app->request;
- Yii::$app->getResponse()->format = 'json';
- $query = (new \yii\db\Query())
- ->select('m_unit.*, m_people.*')
- ->from("m_people")
- ->leftJoin('m_unit', 'm_unit.id = unit_id');
- // searching
- if (($q = $request->post('q'))) {
- }
- if (($request->post('searchtype') == 'str')) {
- $query->andFilterWhere(['like', 'LOWER(' . $request->post('searchdata') . ')', strtolower($request->post('searchvalue'))]);
- } else if (($request->post('searchtype') == 'int')) {
- $query->andFilterWhere([$request->post('searchdata') => $request->post('searchvalue')]);
- }
- // sorting
- if (($sort = $request->post('sort'))) {
- $order = $request->post('order', 'asc');
- $query->orderBy([$sort => $order == 'asc' ? SORT_ASC : SORT_DESC]);
- } else {
- }
- // paging
- $limit = $request->post('rows', 15);
- $page = $request->post('page', 1);
- $total = $query->count();
- $query->offset(($page - 1) * $limit)->limit($limit);
- return [
- 'total' => $total,
- 'rows' => $query->all(),
- ];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement