addBehavior( new SoftDelete([ 'field' => 'deleted', 'value' => 1, ]) ); } public function beforeCreate() { $this->salt = Password::salt(); $this->password = Password::hash($this->password, $this->salt); $this->create_time = time(); } public function beforeUpdate() { if (!empty($this->password)) { $this->salt = Password::salt(); $this->password = Password::hash($this->password, $this->salt); } $this->update_time = time(); } public function afterCreate() { $user = new User(); $user->id = $this->id; $user->name = "user_{$this->id}"; $user->create(); } }