class User extends ActiveRecord implements \yii\web\IdentityInterface
{
public $id;
public $username;
public $password;
public $authKey;
public $accessToken;
public $permissions;
private static $current_user = [
'id' => false,
'username' => false,
'password' => false,
'authKey' => false,
'accessToken' => false,
'permissions' => false,
];
//...
public function setPassword($username, $new_password)
{
$user = new User();
$user = User::find(['username'=>$username])->one();
var_dump($user);
if($user){
$user->password= Yii::$app->getSecurity()->generatePasswordHash($new_password);
$user->save();
return 1;
}
return null;
}
}
Дамп выдаёт следующее:
object(app\models\User)#241 (15) { ["id"]=> NULL ["password"]=> NULL ["authKey"]=> NULL ["accessToken"]=> NULL ["permissions"]=> NULL ["_attributes":"yii\db\BaseActiveRecord":private]=> array(5) { ["id"]=> int(1) ["username"]=> string(5) "zorro" ["password"]=> string(60) "$2y$13$ycaghC0uigV2pgWyT2lmIOHXYPVsclzVejgAGSnWESjPPYUFwRlBq" ["permissions"]=> string(2) "ad" ["description"]=> NULL } ["_oldAttributes":"yii\db\BaseActiveRecord":private]=> array(5) { ["id"]=> int(1) ["username"]=> string(5) "zorro" ["password"]=> string(60) "$2y$13$ycaghC0uigV2pgWyT2lmIOHXYPVsclzVejgAGSnWESjPPYUFwRlBq" ["permissions"]=> string(2) "ad" ["description"]=> NULL } ["_related":"yii\db\BaseActiveRecord":private]=> array(0) { } ["_relationsDependencies":"yii\db\BaseActiveRecord":private]=> array(0) { } ["_errors":"yii\base\Model":private]=> NULL ["_validators":"yii\base\Model":private]=> NULL ["_scenario":"yii\base\Model":private]=> string(7) "default" ["_events":"yii\base\Component":private]=> array(0) { } ["_eventWildcards":"yii\base\Component":private]=> array(0) { } ["_behaviors":"yii\base\Component":private]=> array(0) { } } object(app\models\User)#262 (15) { ["id"]=> NULL ["password"]=> NULL ["authKey"]=> NULL ["accessToken"]=> NULL ["permissions"]=> NULL ["_attributes":"yii\db\BaseActiveRecord":private]=> array(5) { ["id"]=> int(1) ["username"]=> string(5) "zorro" ["password"]=> string(60) "$2y$13$ycaghC0uigV2pgWyT2lmIOHXYPVsclzVejgAGSnWESjPPYUFwRlBq" ["permissions"]=> string(2) "ad" ["description"]=> NULL } ["_oldAttributes":"yii\db\BaseActiveRecord":private]=> array(5) { ["id"]=> int(1) ["username"]=> string(5) "zorro" ["password"]=> string(60) "$2y$13$ycaghC0uigV2pgWyT2lmIOHXYPVsclzVejgAGSnWESjPPYUFwRlBq" ["permissions"]=> string(2) "ad" ["description"]=> NULL } ["_related":"yii\db\BaseActiveRecord":private]=> array(0) { } ["_relationsDependencies":"yii\db\BaseActiveRecord":private]=> array(0) { } ["_errors":"yii\base\Model":private]=> NULL ["_validators":"yii\base\Model":private]=> NULL ["_scenario":"yii\base\Model":private]=> string(7) "default" ["_events":"yii\base\Component":private]=> array(0) { } ["_eventWildcards":"yii\base\Component":private]=> array(0) { } ["_behaviors":"yii\base\Component":private]=> array(0) { } }
Простым вызовом $user->id я не могу вызвать свойства, там везде null. Если ставить find()->isArray(), данные выводятся нормально в массиве. Как мне сделать, чтобы можно было вызвать через свойства и потом сохранять через $user->save()?