谁一开始就是大神?

saveattributes['id']方法获取不到id号[2.0]

$userOpenId = new UserOpenId([
    'openid'=>(string)$openId,
    'opentype'=>$openType,
    'userName'=>$userName
]);
if($userOpenId->save()){
    $id = $userOpenId->attributes['id'];var_dump($id);exit;
}

public function rules()
{
    return [
        [['id'], 'integer'],
        [['userId'], 'integer'],
        [['opentype'], 'string', 'max' => 60],
        [['userName'], 'string', 'max' => 60],
        [['openhash'], 'string', 'max' => 32],
        [['openid'], 'string', 'max' => 255],
        [['opentype', 'openhash'], 'unique', 'targetAttribute' => ['opentype', 'openhash'], 'message' => 'The combination of Opentype and Openhash has already been taken.'],
    ];
}

id 在数据库里有没有设置为自动递增

赞(0) 打赏
未经允许不得转载:菜鸟之家 » saveattributes['id']方法获取不到id号[2.0]

评论 抢沙发

登录

找回密码

注册