コード例 #1
0
ファイル: ProfileForm.php プロジェクト: guillemc/yii2starter
 public function validateUnique($attribute, $params)
 {
     $query = Admin::find();
     /* @var $query \yii\db\ActiveQuery */
     $query->where([$attribute => $this->{$attribute}]);
     if (!$this->_user->isNewRecord) {
         $query->andWhere(['!=', 'id', $this->_user->id]);
     }
     if ($query->exists()) {
         $this->addError($attribute, Yii::t('admin', '{attribute} "{value}" is already in use.', ['attribute' => $this->getAttributeLabel($attribute), 'value' => $this->{$attribute}]));
     }
 }
コード例 #2
0
ファイル: AdminSearch.php プロジェクト: guillemc/yii2starter
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params, $options = [])
 {
     $query = Admin::find();
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => isset($options['pageSize']) ? $options['pageSize'] : 20]]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     $query->andFilterWhere(['like', 'username', $this->username])->andFilterWhere(['like', 'email', $this->email]);
     return $dataProvider;
 }