public function run() { $ads = Ads::find()->where('url = :url', [':url' => $this->url])->one(); if ($ads == null) { return ""; } return $this->render('ads', ['code' => $ads->code]); }
public function actionIndex() { $query = Ads::find()->where(['deleted' => Ads::NO_DELETED])->orderBy('created_at'); $countQuery = clone $query; $pages = new Pagination(['totalCount' => $countQuery->count()]); $pages->setPageSize(20); $ads = $query->offset($pages->offset)->limit($pages->limit)->all(); return $this->render('index', ['ads' => $ads, 'pages' => $pages]); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Ads::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id]); $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'url', $this->url])->andFilterWhere(['like', 'code', $this->code]); return $dataProvider; }