public function actionIndex($id = NULL) { if (isset($id)) { $dataProvider = new ActiveDataProvider(['query' => News::find()->where(['status' => News::STATUS_PUBLISH, 'category_id' => $id]), 'pagination' => ['pageSize' => 10]]); } else { $dataProvider = new ActiveDataProvider(['query' => News::find()->where(['status' => News::STATUS_PUBLISH]), 'pagination' => ['pageSize' => 10]]); } // передаём список категорий для отображения в виджете $category = new ActiveDataProvider(['query' => NewsCategory::find()]); return $this->render('index', ['dataProvider' => $dataProvider, 'category' => $category]); }
<?php if ($model->image) { echo '<img src="' . \Yii::$app->request->BaseUrl . '/' . $model->image . '" width="120px" height="120px">'; } ?> <?php echo $form->field($model, 'short')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'text')->textarea(['rows' => 6]); ?> <?php echo $form->field($model, 'category_id')->dropDownList(ArrayHelper::map(NewsCategory::find()->all(), 'id', 'name')); ?> <?php echo $form->field($model, 'slug')->textInput(['maxlength' => true]); ?> <?php if (Yii::$app->user->identity->role_id == 1) { ?> <?php echo $form->field($model, 'status')->checkbox(); ?>
public function actionIndex() { $dataProvider = new ActiveDataProvider(['query' => NewsCategory::find()]); return $this->render('index', ['dataProvider' => $dataProvider]); }