2017-01-14 10:28:33 2991次浏览 1条回答 0 悬赏 10 金钱
$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.'],
    ];
}

最佳答案

  • 发布于 2017-01-14 11:12 举报

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

    1 条回复
    回复于 2017-01-14 11:54 回复

    感觉你的提示了我,不是自动递增的问题,是原来设置表的人尽然没有设置为主键。。。

    没有找到数据。
您需要登录后才可以回答。登录 | 立即注册
kevin19a
助理

kevin19a

注册时间:2016-12-22
最后登录:2017-11-20
在线时长:5小时12分
  • 粉丝0
  • 金钱130
  • 威望0
  • 积分180

热门问题