SHARE
TWEET

Yii2 Grid Jeasyui - Controller

haifahrul Aug 22nd, 2019 127 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public function actionGetData()
  2.     {
  3.         $request = Yii::$app->request;
  4.         Yii::$app->getResponse()->format = 'json';
  5.         $query = (new \yii\db\Query())
  6.             ->select('m_unit.*, m_people.*')
  7.             ->from("m_people")
  8.         ->leftJoin('m_unit', 'm_unit.id = unit_id');
  9.         // searching
  10.         if (($q = $request->post('q'))) {
  11.         }
  12.  
  13.         if (($request->post('searchtype') == 'str')) {
  14.             $query->andFilterWhere(['like', 'LOWER(' . $request->post('searchdata') . ')', strtolower($request->post('searchvalue'))]);
  15.         } else if (($request->post('searchtype') == 'int')) {
  16.             $query->andFilterWhere([$request->post('searchdata') => $request->post('searchvalue')]);
  17.         }
  18.  
  19.         // sorting
  20.         if (($sort = $request->post('sort'))) {
  21.             $order = $request->post('order', 'asc');
  22.             $query->orderBy([$sort => $order == 'asc' ? SORT_ASC : SORT_DESC]);
  23.         } else {
  24.         }
  25.  
  26.         // paging
  27.         $limit = $request->post('rows', 15);
  28.         $page = $request->post('page', 1);
  29.         $total = $query->count();
  30.         $query->offset(($page - 1) * $limit)->limit($limit);
  31.         return [
  32.             'total' => $total,
  33.             'rows' => $query->all(),
  34.         ];
  35.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top