Answer the question
In order to leave comments, you need to log in
Yii2 if there is a special method that changes only those fields in the database for which the data came?
email,lastName,firstName ,middleName,birthday ,password method changes these fields in the table. Is there a method that allows you to change fields without using if to check for null?
class ChangeCustomer extends Model
{
public $email;
public $_csrf;
public $firstName;
public $lastName;
public $middleName;
public $birthday;
public $password;
public function rules(){
return[
['_csrf','required'],
['email','email'],
['email','unique','targetClass' => Customer::className()],
[['lastName','firstName','middleName','birthday','password'],'safe'],
];
}
//Если значения будут null которые менять не надо то проверять только if?
public function change(){
$user = Customer::findIdentityByAccessToken($this->_csrf);
$user->email = $this->email;
$user->lastName = $this->lastName;
$user->firstName = $this->firstName;
$user->middleName = $this->middleName;
$user->birthday = $this->birthday;
$user->password = $this->password;
return $user->save();
}
}
Answer the question
In order to leave comments, you need to log in
You can write your own load method instead of the standard one and check there, but you are solving the wrong problem. Your problem is that you're getting null, which shouldn't be. Where did null come from in your post request?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question