public function getPossiblePositions() { $positions = []; foreach (Ad::find()->select("position")->distinct()->asArray()->all() as $position) { $positions[$position['position']] = $position['position']; } return $positions; }
/** * Lists all Ad models. * @return mixed */ public function actionIndex() { if (!$this->is_access('ads/index')) { Yii::$app->session->setFlash('error', $this->errorInfo); return $this->redirect($this->redirectUrl); } $query = Ad::find(); if ($position_id = Yii::$app->request->get('position_id')) { $query = $query->where(['position_id' => $position_id]); } $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['ad_id' => SORT_DESC]]]); Yii::$app->view->params['meta_title'] = '广告列表'; return $this->render('index', ['dataProvider' => $dataProvider]); }
/** * @return \yii\db\ActiveQuery|ActiveRecord */ public static function find() { $time = time(); return parent::find()->where("`disableDate` >= '{$time}' OR `disableDate` = '0'")->andWhere(['state' => 1]); }
/** * Renders the index view for the module * @return string */ public function actionIndex() { return $this->render('index', ['ads' => new ActiveDataProvider(['query' => Ad::find()])]); }