findOne() 的问题 [ 2.0 版本 ]
public static function findByUsername($username)
{
return static::findOne(['username'=>$username]);
}
public function getUser()
{
if ($this->_user === false) {
$this->_user = User::findByUsername($this->username);
var_dump($this->_user);
}
return $this->_user;
}
代码如上:
var_dump出来的值如下:
public 'id' => null
public 'username' => null
public 'password' => null
public 'authKey' => null
public 'accessToken' => null
private '_attributes' (yii\db\BaseActiveRecord) =>
array (size=5)
'id' => int 1
'username' => string 'hello' (length=5)
'password' => string 'hello' (length=5)
'auth_key' => null
'accessToken' => null
private '_oldAttributes' (yii\db\BaseActiveRecord) =>
array (size=5)
'id' => int 1
'username' => string 'hello' (length=5)
'password' => string 'hello' (length=5)
'auth_key' => null
'accessToken' => null
private '_related' (yii\db\BaseActiveRecord) =>
array (size=0)
empty
private '_errors' (yii\base\Model) => null
private '_validators' (yii\base\Model) => null
private '_scenario' (yii\base\Model) => string 'default' (length=7)
private '_events' (yii\base\Component) =>
array (size=0)
empty
private '_behaviors' (yii\base\Component) =>
array (size=0)
empty
疑问:
findOne
出来的值,是否正确,我想取出password
这个字段该怎么做?
共 3 个回答
yii_song
注册时间:2016-05-08
最后登录:2018-09-14
在线时长:35小时17分
最后登录:2018-09-14
在线时长:35小时17分
- 粉丝4
- 金钱3820
- 威望10
- 积分4270