protected function findModel($id) { if (($model = NewsCategory::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
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]); }
} else { ?> <div class="news_banner"> <?php } ?> </div> <!--banner--> <!--注册人数--> <div class="register_number"> <div class="nav_sets"> 您现在的位置:<a href="<?php echo \yii\helpers\Url::to('/home/index'); ?> " style="color:#008000;">首页</a><b>></b><?php echo \app\models\NewsCategory::getOneCategoryNameById($data['categoryId']); ?> </div> </div> <!--注册人数--> <!--content--> <div class="content_box"> <div class="con_set"> <div class="news_con"> <!--adv--> <div class="adv0"> <div class="adv_s"> <div class="leftLoop"> <div class="bd"> <ul class="picList"> <?php
<!--banner--> <div class="news_banner"> </div> <!--banner--> <!--注册人数--> <div class="register_number"> <div class="nav_sets"> 您现在的位置:<a href="<?php echo \yii\helpers\Url::to('/home/index'); ?> " style="color:#008000;">首页</a><b>></b><a href="<?php echo \yii\helpers\Url::to(['/news/list', 'category_id' => $newInfo['category_id']]); ?> "><?php echo \app\models\NewsCategory::getOneCategoryNameById($newInfo['category_id']); ?> </a><b>></b><?php echo $newInfo['title']; ?> </div> </div> <!--注册人数--> <!--content--> <div class="content_box"> <div class="con_set"> <div class="news_con"> <h1 class="cont_h1title"><?php echo $newInfo['title']; ?> </h1> <p class="time_date"><?php
/** * @param $input * @return bool */ public function createCategory($input) { $category = new NewsCategory(); $category->name = $input['name']; $category->pid = $input['pid']; return $category->save(); }
/** * @return \yii\db\ActiveQuery */ public function getCategory() { return $this->hasOne(NewsCategory::className(), ['id' => 'category_id']); }
/* @var $model app\models\News */ /* @var $form yii\widgets\ActiveForm */ ?> <div class="news-form"> <?php $form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]); ?> <?php echo $form->field($model, 'title')->textInput(['style' => 'width:300px']); ?> <?php echo $form->field($model, 'category_id')->dropDownList(ArrayHelper::map(\app\models\NewsCategory::getAll(), 'id', 'name'), ['style' => 'width:200px']); ?> <?php echo $form->field($model, 'content')->widget(KindEditor::className(), ['clientOptions' => ['allowFileManager' => 'true', 'allowUpload' => 'true']]); ?> <?php echo $form->field($model, 'status')->dropDownList(\app\models\News::$statusList, ['style' => 'width:100px']); ?> <?php if (!$model->isNewRecord && !empty($model->thumb)) { ?> <a href="#"><img src="/upload/images/news/thumb/<?php echo $model->thumb; ?>
<?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(); ?>