Answer the question
In order to leave comments, you need to log in
Yii2, in Active Records how to select the desired properties?
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) { } }
Answer the question
In order to leave comments, you need to log in
And if you remove the properties that you have in the database? for ActiveRecord models, you can omit properties so that auto-substitution works, you can use php-doc
/**
* Class User
* @property $username string
*/
class User extends ActiveRecord implements \yii\web\IdentityInterface
{
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question