mirror of
https://github.com/yiisoft/yii2.git
synced 2025-08-26 14:26:54 +08:00
Moved creating user to static method of the model
This commit is contained in:
@ -27,6 +27,18 @@ class User extends ActiveRecord implements IdentityInterface
|
|||||||
|
|
||||||
const ROLE_USER = 10;
|
const ROLE_USER = 10;
|
||||||
|
|
||||||
|
public static function create($attributes)
|
||||||
|
{
|
||||||
|
/** @var User $user */
|
||||||
|
$user = new static();
|
||||||
|
$user->setAttributes($attributes);
|
||||||
|
if ($user->save()) {
|
||||||
|
return $user;
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritdoc
|
* @inheritdoc
|
||||||
*/
|
*/
|
||||||
|
@ -41,10 +41,7 @@ class SignupForm extends Model
|
|||||||
public function signup()
|
public function signup()
|
||||||
{
|
{
|
||||||
if ($this->validate()) {
|
if ($this->validate()) {
|
||||||
$user = User::create($this->attributes);
|
return User::create($this->attributes);
|
||||||
if ($user->save()) {
|
|
||||||
return $user;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user