Exemplo n.º 1
0
 public function getAdr($condition)
 {
     return Advertisement::find()->where($condition)->asArray()->one();
 }
 public function actionSearch()
 {
     \Yii::$app->response->format = Response::FORMAT_JSON;
     $params = $this->getParams();
     $page = isset($params['page']) ? $params['page'] : 1;
     $page = empty($page) ? 1 : $page;
     unset($params['page']);
     $conditions = array_filter($params, function ($val) {
         if (empty($val)) {
             return false;
         }
         return true;
     });
     $size = 9;
     $offset = ($page - 1) * $size;
     $orderby = " id DESC";
     if (!empty($conditions) && isset($conditions['archive_name']) && !empty($conditions['archive_name'])) {
         $archive_name_arr = ['LIKE', 'archive_name', $conditions['archive_name']];
         unset($conditions['archive_name']);
         $conditions[] = $archive_name_arr;
     }
     $advertisement = new Advertisement();
     $returns = $advertisement->getAds($conditions, $offset, $size, $orderby);
     $advertisements = empty($returns['list']) ? [] : $returns['list'];
     $total = $returns['total'];
     $pageHTML = $this->getPageHTML($page, $size, $total);
     return ['advertisements' => $advertisements, 'pageHTML' => $pageHTML];
 }