Работаю в Yii недавно, мог сделать что-то не то.
Пытаюсь сделать регистрацию пользователя:
Код: Выделить всё
$user = new User();
$user->email = $this->email;
$user->password = Yii::$app->security->generatePasswordHash($this->password);
Yii::debug(print_r($user,1));
$user->save();
Код: Выделить всё
INSERT INTO `user` (`id`) VALUES (DEFAULT)
Код: Выделить всё
CREATE TABLE `user` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`email` varchar(180) COLLATE utf8mb4_unicode_ci NOT NULL,
`roles` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL,
`password` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `email` (`email`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
Код: Выделить всё
class User extends ActiveRecord implements \yii\web\IdentityInterface
{
public $id;
public $email;
public $password;
public $authKey;
public $accessToken;
public static function tableName()
{
return 'user';
}
public function rules()
{
return [
[ ['password', 'email'], 'required']
];
}
/**
* {@inheritdoc}
*/
public static function findIdentity($id)
{
return static::findOne($id);
}
/**
* {@inheritdoc}
*/
public static function findIdentityByAccessToken($token, $type = null)
{
return null;
}
/**
* Finds user by username
*
* @param string $username
* @return static|null
*/
public static function findByUsername($username)
{
return static::findOne(['email' => $username]);
}
/**
* {@inheritdoc}
*/
public function getId()
{
return $this->id;
}
/**
* {@inheritdoc}
*/
public function getAuthKey()
{
return $this->authKey;
}
/**
* {@inheritdoc}
*/
public function validateAuthKey($authKey)
{
return $this->authKey === $authKey;
}
/**
* Validates password
*
* @param string $password password to validate
* @return bool if password provided is valid for current user
*/
public function validatePassword($password)
{
return \Yii::$app->security->validatePassword($password, $this->password);
}
}
Код: Выделить всё
app\\models\\User Object
(
[id] =>
[email] => [отцензурено]
[password] => [отцензурено]
[authKey] =>
[accessToken] =>
[_attributes:yii\\db\\BaseActiveRecord:private] => Array
(
)
[_oldAttributes:yii\\db\\BaseActiveRecord:private] =>
[_related:yii\\db\\BaseActiveRecord:private] => Array
(
)
[_relationsDependencies:yii\\db\\BaseActiveRecord:private] => Array
(
)
[_errors:yii\\base\\Model:private] =>
[_validators:yii\\base\\Model:private] =>
[_scenario:yii\\base\\Model:private] => default
[_events:yii\\base\\Component:private] => Array
(
)
[_eventWildcards:yii\\base\\Component:private] => Array
(
)
[_behaviors:yii\\base\\Component:private] => Array
(
)
)