public function actionPreview($id, $category_id) { $model = $this->findModel($id); $category = CmsFaqCategories::findOne(['id' => $category_id]); $this->layout = 'preview'; return $this->render('@frontend/views/faq/view', ['model' => $model, 'category' => $category]); }
/** * Updates an existing CmsFaq model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id * @return mixed */ public function actionUpdate($id, $category_id) { $model = $this->findModel($id); $categoryModel = CmsFaqCategories::findOne($category_id); if ($model->load(Yii::$app->request->post()) && $model->save()) { Yii::$app->getSession()->setFlash('success', 'Successfully updated.'); return $this->redirect(['cms-faq/update', 'id' => $model->id, 'category_id' => $category_id]); } $languages = Lang::find()->all(); $languageDefault = Lang::findOne(['default' => 1]); return $this->render('update', ['model' => $model, 'languages' => $languages, 'languageDefault' => $languageDefault, 'categoryModel' => $categoryModel]); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = CmsFaqCategories::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, 'status' => $this->status, 'sort_order' => $this->sort_order, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]); $query->andFilterWhere(['like', 'title', $this->title]); return $dataProvider; }
/** * Finds the CmsFaqCategories model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return CmsFaqCategories the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = CmsFaqCategories::find()->where(['id' => $id])->multilingual()->one()) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
$language_items = []; $redactorClientOptions = ['imageManagerJson' => ['/redactor/upload/image-json'], 'imageUpload' => ['/redactor/upload/image'], 'fileUpload' => ['/redactor/upload/file'], 'lang' => Yii::$app->language, 'plugins' => ['fontsize', 'bufferbuttons', 'fontcolor', 'imagemanager', 'emotions']]; foreach ($languages as $key => $language) { $field_title = $form->field($model, "title_{$language->url}")->textInput(['maxlength' => true])->label('FAQ Title'); $field_content = $form->field($model, "content_{$language->url}")->widget(\yii\redactor\widgets\Redactor::className(), ['clientOptions' => $redactorClientOptions]); if ($languageDefault->url == $language->url) { $field_title = $form->field($model, "title")->textInput(['maxlength' => true]); $field_content = $form->field($model, 'content')->widget(\yii\redactor\widgets\Redactor::className(), ['clientOptions' => $redactorClientOptions]); } $language_items[] = ['label' => Yii::t('backend', $language->name), 'content' => "<p>{$field_title} {$field_content}</p>", 'active' => $language->url == Yii::$app->language]; } echo Tabs::widget(['items' => $language_items]); ?> <?php echo $form->field($model, 'category_id')->dropDownList(ArrayHelper::map(\backend\models\CmsFaqCategories::find()->all(), 'id', 'title'), ['multiple' => 'true', 'size' => 7])->label(Yii::t('backend', 'Select Categories')); ?> <?php echo $form->field($model, 'identifier')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'sort_order')->textInput(); ?> <?php echo $form->field($model, 'is_active')->checkbox(['label' => Yii::t('backend', 'Active')]); ?> <div class="form-group">
use yii\grid\GridView; use backend\models\CmsFaqCategories; /* @var $this yii\web\View */ /* @var $dataProvider yii\data\ActiveDataProvider */ $this->title = Yii::t('backend', 'FAQ Categories'); $this->params['breadcrumbs'][] = $this->title; ?> <div class="cms-faq-categories-index"> <h1><?php echo Html::encode($this->title); ?> </h1> <p> <?php echo Html::a(Yii::t('backend', 'Create Category'), ['create'], ['class' => 'btn btn-success']); ?> <?php echo Html::a(Yii::t('backend', 'Create FAQ'), ['cms-faq/create'], ['class' => 'btn btn-primary']); ?> </p> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], 'id', 'title', ['attribute' => 'status', 'filter' => Html::activeDropDownList($searchModel, 'status', CmsFaqCategories::dropdownActive(), ['class' => 'form-control', 'prompt' => Yii::t('backend', 'All')]), 'value' => 'statusLabel'], 'sort_order', ['class' => 'yii\\grid\\ActionColumn', 'urlCreator' => function ($action, $model, $key, $index) { return $action == 'view' ? ['cms-faq-categories/' . $action, 'category_id' => $model['id']] : ['cms-faq-categories/' . $action, 'id' => $model['id']]; }]]]); ?> </div>