/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = DiscoveryTranslation::find(); if (!empty($params['discovery_id'])) { $query->where(['discovery_id' => $params['discovery_id']]); } $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['id' => SORT_DESC]]]); $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, 'language_id' => $this->language_id, 'discovery_id' => $this->discovery_id]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'content', $this->content])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'search_text', $this->search_text])->andFilterWhere(['like', 'page_title', $this->page_title])->andFilterWhere(['like', 'h1', $this->h1])->andFilterWhere(['like', 'meta_title', $this->meta_title])->andFilterWhere(['like', 'meta_description', $this->meta_description])->andFilterWhere(['like', 'meta_keywords', $this->meta_keywords])->andFilterWhere(['like', 'image_path', $this->image_path])->andFilterWhere(['like', 'caption', $this->caption]); return $dataProvider; }
use yii\web\View; use yii\widgets\ActiveForm; /* @var $this View */ /* @var $model DiscoveryTranslation */ /* @var $form ActiveForm */ ?> <div class="discovery-translation-form"> <?php $form = ActiveForm::begin(); ?> <div class="col-md-6"> <?php echo $form->field($model, 'language_id')->dropDownList(array_diff_key($this->context->languages_idToName, ArrayHelper::map(DiscoveryTranslation::find()->where(['discovery_id' => $model->discovery_id])->andWhere(['<>', 'id', (int) $model->id])->all(), 'language_id', 'language_id'))); ?> <?php echo $form->field($model, 'discovery_id')->textInput(['readonly' => true, 'type' => 'hidden'])->label(false); ?> <?php echo $form->field($model, 'name')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'caption')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, 'description')->textarea(['maxlength' => true, 'rows' => 3, 'style' => 'resize:vertical']); ?> <?php // echo $form->field($model, 'search_text')->textInput(['maxlength' => true])