public function actionNews() { $slug = Yii::$app->getRequest()->getQueryParam('slug'); $slug = str_replace(".html", "", $slug); if ($slug) { $model = News::find()->where(['slug' => $slug])->one(); return $this->render('newsshow', ['model' => $model]); } else { $newsQuery = News::find(); $DataProvider = new ActiveDataProvider(['query' => $newsQuery, 'pagination' => ['pageSize' => 5]]); return $this->render('news', ['DataProvider' => $DataProvider]); } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = News::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, 'date' => $this->date, 'status' => $this->status, 'position' => $this->position, 'type' => $this->type, 'arhive' => $this->arhive, 'in_home' => $this->in_home, 'event_date' => $this->event_date]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['=', 'date', $this->date]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = News::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, 'data' => $this->data]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'shorttext', $this->shorttext])->andFilterWhere(['like', 'longertext', $this->longertext]); return $dataProvider; }
/** * Finds the News model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return News the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = News::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function actionOnenews() { $query = News::findOne($_GET['id']); return $this->render('onenews', ['query' => $query]); }