Example #1
0
 public function actionGet_data()
 {
     //      var_dump($_POST);
     $count = Food::model()->count();
     $criteria = new CDbCriteria();
     if ($_POST['searchPhrase'] != '') {
         $criteria->condition = 'title like ' . '"%' . $_POST['searchPhrase'] . '%" or  port like ' . '"%' . $_POST['searchPhrase'] . '%"';
     }
     if (isset($_POST['sort']['id'])) {
         $criteria->order = " id  {$_POST['sort']['id']} ";
     } else {
         if (isset($_POST['sort']['title'])) {
             $criteria->order = "title {$_POST['sort']['title']} ";
         } else {
             if (isset($_POST['sort']['port'])) {
                 $criteria->order = "port {$_POST['sort']['port']} ";
             }
         }
     }
     $criteria->limit = $_POST['rowCount'];
     $criteria->offset = (intval($_POST['current']) - 1) * $_POST['rowCount'];
     $model = Food::model()->findAll($criteria);
     //      var_dump($model);
     $arr = array();
     foreach ($model as $o) {
         $json = array('id' => intval($o->id), 'title' => $o->title, 'port' => $o->port);
         array_push($arr, $json);
     }
     //      var_dump( $arr);
     echo json_encode(array('rowCount' => $_POST['rowCount'], 'current' => $_POST['current'], 'rows' => $arr, 'total' => $count));
 }