public function actionIndex() { $limit = 10; // Make Latest Ads $latestAds = Ad::find()->where(['status' => Ad::STATUS_ACTIVE])->orderBy(['id' => SORT_DESC])->limit($limit)->all(); // Most Popular Ads $popularAds = Ad::find()->where(['status' => Ad::STATUS_ACTIVE])->orderBy(['view_count' => SORT_DESC])->limit($limit)->all(); // Random Ads $randomAds = Ad::find()->where(['status' => Ad::STATUS_ACTIVE])->orderBy(['rand()' => SORT_DESC])->limit($limit)->all(); return $this->render('index', ['categories' => Category::findAll(['status' => 1]), 'latestAds' => $latestAds, 'popularAds' => $popularAds, 'randomAds' => $randomAds]); }
/** * Lists all Category models. * @return mixed */ public function actionIndex($id, $location = null) { $categories = Category::find(['status' => 1])->joinWith(['subcategories'])->all(); $where = ['subcategory_id' => $id]; if (!is_null($location)) { $where['location_id'] = $location; } $ads = Ad::find()->where($where)->joinWith(['adsImages'])->all(); // $ads = Ad::find(['subcategory_id'=> 1]) // ->all(); return $this->render('index', ['categories' => $categories, 'ads' => $ads]); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Ad::find(); $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 10]]); $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, 'subcategory_id' => $this->subcategory_id, 'user_id' => $this->user_id, 'location_id' => $this->location_id, 'price' => $this->price, 'view_count' => $this->view_count, 'status' => $this->status, 'date_created' => $this->date_created, 'date_expired' => $this->date_expired]); $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['>', 'price', $this->min_price])->andFilterWhere(['<', 'price', $this->max_price])->andFilterWhere(['>', 'view_count', $this->min_view_count])->andFilterWhere(['<', 'view_count', $this->max_view_count])->andFilterWhere(['>', 'date_created', $this->min_date_created])->andFilterWhere(['<', 'date_created', $this->max_date_created])->andFilterWhere(['>', 'date_expired', $this->min_date_expired])->andFilterWhere(['<', 'date_expired', $this->max_date_expired]); return $dataProvider; }
/** * Lists all Ad models. * @return mixed */ public function actionIndex() { $dataProvider = new ActiveDataProvider(['query' => Ad::find()]); return $this->render('index', ['dataProvider' => $dataProvider]); }