public function actionCategory($id) { /** * Define default member group code */ $faqQuery = \backend\models\CmsFaq::find()->where(['is_active' => 1]); $faqQuery->andWhere(['like', 'category_id', "[{$id}]"]); $dataProvider = new ActiveDataProvider(['query' => $faqQuery, 'sort' => ['defaultOrder' => ['sort_order' => SORT_ASC, 'updated_at' => SORT_ASC]]]); $category = CmsFaqCategories::find($id)->one(); return $this->render('index', ['dataProvider' => $dataProvider, 'category' => $category]); }
/** * 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">