public function rules()
{
return [
[['access', 'active', 'published'], 'integer'],
[['about'], 'string'],
...
...
...
...
...
...
...
[['about'], 'checkEmpty'],
[['published'], 'checkConditionsPublished'],
[['access'], 'checkConditionsAccess'],
[['active'], 'checkConditionsActive'],
];
}
public function checkConditionsAccess($attribute){ //echo 'access'; exit;
if (Yii::$app->user->identity->access != 1){
if ($this->$attribute != $this->getOldAttribute($attribute)){
$this->addError($attribute, 'Permission denied! You can\'t change your access!');
}
}
elseif ($this->access == 1){
if ($this->published == ''){
$this->addError($attribute, 'To set user as "Admin" or "Writer" first you must set field "Published"!');
}
}
}
public function checkConditionsActive($attribute){ //echo 'active'; exit;
if (Yii::$app->user->identity->access != 1){
if ($this->$attribute != $this->getOldAttribute($attribute)){
$this->addError($attribute, 'Permission denied! You can\'t change your activities!');
}
}
elseif ($this->active == 1){
if ($this->access == 1 || $this->access == 2) {
if (!$this->photo){
$this->addError($attribute, 'To activate user first you must upload avatar!');
}
}
if (!$this->access) {
$this->addError($attribute, 'To activate user first you must set access!');
}
}
}
public function checkConditionsPublished($attribute){//echo 'published'; exit;
if (Yii::$app->user->identity->access != 1){
if ($this->$attribute != $this->getOldAttribute($attribute)){
$this->addError($attribute, 'Permission denied! You can\'t set this field!');
}
}
if ($this->$attribute == 1) {
if (!$this->photo) {
$this->addError($attribute, 'To set user as published author first you must upload avatar!');
}
if ($this->access == 3) {
$this->addError($attribute, 'To set user as published author first you must set access as "Admin" or "Writer"');
}
}
}
public function checkEmpty($attribute){// echo 'checkEmpty'; exit;
if (!$this->isNewRecord) {
if (!$this->$attribute)
$this->addError($attribute, 'About cen not be blank!');
}
}
Я заметил, что валидатор напимер checkConditionsAccess не срабатыват только тогда когда полю 'access' пытаются присвоить пустую строку, но когда приходит не пустая строка, то этот валидатор работает нормально. Так же происходит и с валидатором checkEmpty.
Подскажите пожплуйста в чем может быть проблема.