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
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度