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

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 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵