/** * Updates an existing KefuFaq model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id * @return mixed */ public function actionUpdate($id) { $model = $this->findModel($id); $categories = KefuFaqCat::find()->all(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('update', ['model' => $model, 'categories' => $categories]); } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = KefuFaqCat::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'parent_id' => $this->parent_id]); $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'slug', $this->slug]); return $dataProvider; }
/** * @return \yii\db\ActiveQuery */ public function getCategory() { return $this->hasOne(KefuFaqCat::className(), ['id' => 'category_id']); }
use yii\helpers\Html; use yii\helpers\ArrayHelper; use yii\grid\GridView; use common\models\KefuFaq; /* @var $this yii\web\View */ /* @var $searchModel backend\models\search\KefuFaqSearch */ /* @var $dataProvider yii\data\ActiveDataProvider */ $this->title = Yii::t('common', 'Kefu Faq'); $this->params['breadcrumbs'][] = $this->title; ?> <div class="kefu-faq-index"> <?php // echo $this->render('_search', ['model' => $searchModel]); ?> <p> <?php echo Html::a(Yii::t('backend', 'Create {modelClass}', ['modelClass' => Yii::t('common', 'Kefu Faq')]), ['create'], ['class' => 'btn btn-success']); ?> </p> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], 'title', ['attribute' => 'category_id', 'value' => function ($model) { return $model->category ? $model->category->title : null; }, 'filter' => ArrayHelper::map(\common\models\KefuFaqCat::find()->all(), 'id', 'title')], 'description', ['class' => \common\grid\EnumColumn::className(), 'attribute' => 'status', 'enum' => KefuFaq::getStatus()], ['class' => 'yii\\grid\\ActionColumn']]]); ?> </div>
/** * 通过客服常用问题分类的slug获取该分类下的所有数据 * @param $categorySlug 客服常用问题分类slug * @param $limit 限制返回的数据个数 * @return array|\yii\db\ActiveRecord[] */ public static function getKefuFaqbyCategorySlug($categorySlug, $limit) { $qiTaWenTis = KefuFaq::find()->where(['status' => KefuFaq::STATUS_IN_USE, 'category_id' => KefuFaqCat::findOne(['slug' => $categorySlug])['id']])->orderBy("created_at DESC")->limit($limit)->all(); return $qiTaWenTis; }
/** * Finds the KefuFaqCat model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return KefuFaqCat the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = KefuFaqCat::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * @return \yii\db\ActiveQuery */ public function getKefuFaqCats() { return $this->hasMany(KefuFaqCat::className(), ['parent_id' => 'id']); }