/** * 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 any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'weight' => $this->weight, 'status_id' => $this->status_id, 'created_at' => $this->created_at, 'created_by' => $this->created_by, 'updated_at' => $this->updated_at, 'updated_by' => $this->updated_by]); $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'preview', $this->preview])->andFilterWhere(['like', 'text', $this->text])->andFilterWhere(['like', 'image', $this->image])->andFilterWhere(['like', 'category_id', $this->category_id])->andFilterWhere(['like', 'tag', $this->tag]); 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, 'at_top' => $this->at_top, 'create_at' => $this->create_at]); $query->andFilterWhere(['like', 'alias', $this->alias])->andFilterWhere(['like', 'header', $this->header])->andFilterWhere(['like', 'short_description', $this->short_description])->andFilterWhere(['like', 'body', $this->body])->andFilterWhere(['like', 'image', $this->image]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = News::find(); // add conditions that should always apply here $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; } // grid filtering conditions $query->andFilterWhere(['id' => $this->id, 'category_id' => $this->category_id, 'date_public' => $this->date_public, 'created_at' => $this->created_at, 'created_by' => $this->created_by, 'updated_at' => $this->updated_at, 'updated_by' => $this->updated_by, 'removed' => $this->removed, 'locked' => $this->locked]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'url', $this->url])->andFilterWhere(['like', 'image', $this->image])->andFilterWhere(['like', 'annotation', $this->annotation])->andFilterWhere(['like', 'content', $this->content])->andFilterWhere(['like', 'layout', $this->layout]); return $dataProvider; }
/** * Finds the News model based on its alias value. * If the model is not found, a 404 HTTP exception will be thrown. * * @param string $alias * @return News the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findByAliasModel($alias) { if (($model = News::findOne(['alias' => $alias])) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * 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.'); } }
<?php use app\modules\news\models; return ['controllerMap' => ['migrate' => ['migrationLookup' => ['@webapp/modules/news/migrations']]], 'modules' => ['news' => ['class' => app\modules\news\News::className(), 'controllerNamespace' => 'app\\modules\\news\\controllers', 'modules' => ['admin' => ['class' => app\modules\news\modules\admin\Admin::className(), 'controllerNamespace' => 'app\\modules\\news\\modules\\admin\\controllers', 'menuItems' => function () { return [['label' => Yii::t('news/app', 'News module'), 'icon' => 'glyphicon glyphicon-align-justify', 'items' => [['label' => Yii::t('news/app', 'News'), 'url' => ['/admin/news/news'], "permission" => ["listModels", ["model" => Yii::createObject(models\News::className())]]], ['label' => Yii::t('news/app', 'News sections'), 'url' => ['/admin/news/news-section'], "permission" => ["listModels", ["model" => Yii::createObject(models\NewsSection::className())]]]]]]; }]]]], 'components' => ['i18n' => ['translations' => ['news/*' => ['class' => 'yii\\i18n\\PhpMessageSource', 'basePath' => '@webapp/modules/news/messages', 'fileMap' => ['news/app' => 'app.php']]]], 'urlManager' => ['rules' => ['news/<section:[A-z0-9_-]+>/<code:[A-z0-9_-]+>' => 'news/news/detail', 'news/<section:[A-z0-9_-]+>' => 'news/news/index', 'news' => 'news/news/index']]]];
/** * Действия * @return array */ public function actions() { $class = News::className(); return ['index' => ['class' => crud\Admin::className(), 'modelClass' => $class], 'create' => ['class' => crud\Create::className(), 'modelClass' => $class], 'update' => ['class' => crud\Update::className(), 'modelClass' => $class], 'view' => ['class' => crud\View::className(), 'modelClass' => $class], 'delete' => ['class' => crud\Delete::className(), 'modelClass' => $class], 'groupdelete' => ['class' => crud\GroupDelete::className(), 'modelClass' => $class], 'editable' => ['class' => crud\XEditable::className(), 'modelClass' => $class]]; }
/** * Отображение детальной новости * @param string $code символьный идентификатор новости * @param string $section символьный идентификатор категории новости * @return string * @throws \yii\web\NotFoundHttpException */ public function actionDetail($code, $section) { $model = News::find()->published()->andWhere(["code" => $code])->one(); if (!$model) { throw new NotFoundHttpException(); } $sectionModel = NewsSection::find()->published()->andWhere(["code" => $section])->one(); $this->view->addBreadCrumbs($sectionModel->getBreadCrumbsItems($sectionModel, function ($model) { return ['/news/news/index', 'section' => $model->code]; })); $this->view->addBreadCrumb(["label" => $model->title, "url" => Url::toRoute(["/news/news/detail", "code" => $code, "section" => $section])]); $this->view->registerMetaTags($model); return $this->render('detail', ["model" => $model, "detailImageWidth" => $this->detailImageWidth]); }