Beispiel #1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = UrlRule::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id]);
     $query->andFilterWhere(['like', 'url', $this->url])->andFilterWhere(['like', 'alias', $this->alias]);
     return $dataProvider;
 }
Beispiel #2
0
 public function validateAlias($event)
 {
     if (Yii::$app->controller->action->id == 'index') {
         return true;
     }
     $url = $this->url;
     $alias = $this->owner->{$this->field} ? $this->owner->{$this->field} : $this->pattern;
     $alias = $this->prepareAlias($alias);
     if ($alias) {
         $model = \backend\models\UrlRule::findByAlias($alias);
         if (isset($model->alias) && $model->url != $url) {
             $this->owner->addError($this->field, "Alias already exist");
             return false;
         }
     }
 }