Beispiel #1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Page::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, 'url' => $this->url]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'content', $this->content]);
     return $dataProvider;
 }
Beispiel #2
0
$form = ActiveForm::begin();
?>

    <?php 
echo $form->field($model, 'name')->textInput(['maxlength' => true]);
?>

    <?php 
echo $form->field($model, 'content')->widget(TinyMCE::className());
?>

    <?php 
if ($model->url !== null) {
    $pages = Page::find()->where(['!=', 'url', $model->url])->all();
} else {
    $pages = Page::find()->all();
}
$usedUrlsIds = array_map(function ($page) {
    return $page->url;
}, $pages);
?>
    <?php 
echo $form->field($model, 'url')->widget(Select2Widget::className(), ['items' => ArrayHelper::map(Url::find()->where(['not in', 'id', $usedUrlsIds])->all(), 'id', 'url')]);
?>

    <div class="form-group">
        <?php 
echo Html::submitButton($model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']);
?>
    </div>