/** * Finds the Reviews model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Reviews the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Reviews::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Reviews::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, 'age' => $this->age, 'visible' => $this->visible]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'company', $this->company])->andFilterWhere(['like', 'content', $this->content]); return $dataProvider; }
<?php use yii\helpers\Html; use yii\grid\GridView; /* @var $this yii\web\View */ /* @var $model \app\modules\cms\models\Reviews */ /* @var $searchModel app\modules\cms\models\ReviewsSearch */ /* @var $dataProvider yii\data\ActiveDataProvider */ $this->title = Yii::t('app', 'Отзывы'); $this->params['breadcrumbs'][] = $this->title; ?> <div class="reviews-index"> <p> <?php echo Html::a(Yii::t('app', 'Добавить отзыв'), ['create'], ['class' => 'btn btn-success']); ?> </p> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], 'id', ['attribute' => 'visible', 'value' => 'visibleView', 'filter' => \app\modules\cms\models\Reviews::visibleList()], ['header' => '', 'value' => function ($model) { return Html::img($model->image->resize('50x50'), ['class' => 'img-circle']); }, 'format' => 'html'], 'name', 'age', 'company', 'content', ['class' => 'yii\\grid\\ActionColumn', 'template' => '{update} {delete}']]]); ?> </div>
public function actionIndex() { $items = Reviews::find()->visible()->orderBy('id')->all(); return $this->render('index', ['items' => $items]); }