douchuoxuan3177 2012-09-22 21:10
浏览 85
已采纳

Yii Framework $ model-> save()仅适用于一个模型

I try to take the facebook information of a user in my databade. I'm in the UserIdentity to control the athentification of the user and i created this method.

<?php
public function insertFbUser()
{
    $user = new User();
        $user->fbId = $this->username['id'];
        $user->username = $this->username['username'];
        $user->email = $this->username['email'];
        $user->password = $this->password;

    $profile = new Profile();
        $profile->first_name = $this->username['first_name'];
        $profile->last_name = $this->username['last_name'];
        $profile->birthday = strtotime($this->username['birthday']);
        $profile->sex = $this->username['gender'];
        $profile->fb_updated_time = strtotime($this->username['updated_time']);
        $profile->fb_verified = $this->username['verified'];
        $profile->fb_educationJson = json_encode($this->username['education']);
        $profile->fb_workJson = json_encode($this->username['work']);

    var_dump($user->save());
    var_dump($profile->save());
}

the var_dump() show me this

boolean true
boolean false

Both models were created with the GII module. I try to only put one prile attribute at a time and it doesn't work too...

There is my DB : http://pastebin.com/u5CNKj9M

Thank you for your help!

  • 写回答

1条回答 默认 最新

  • dongqian5639 2012-09-22 21:15
    关注

    print_r($profile->getErrors());

    (Update)To get user id after saving:

    $user->save();
    $user_id = $user->id
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题