Beispiel #1
0
 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]);
 }
Beispiel #3
0
 /**
  * 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;
 }
Beispiel #4
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getAds()
 {
     return $this->hasMany(Ads::className(), ['id' => 'ad_id'])->viaTable('ads_reviews', ['user_id' => 'id']);
 }
Beispiel #5
0
 /**
  * Finds the Ads model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Ads the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Ads::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }