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

时间:2012-09-22 21:10:51

标签: php database frameworks model yii

我尝试在我的数据库中获取用户的facebook信息。我在UserIdentity中控制用户的身份验证,我创建了这个方法。

<?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());
}

var_dump()告诉我这个

boolean true
boolean false

两个模型都是使用GII模块创建的。我尝试一次只放一个prile属性,它也不起作用......

我的数据库:http://pastebin.com/u5CNKj9M

感谢您的帮助!

1 个答案:

答案 0 :(得分:4)

print_r($profile->getErrors());

(更新)保存后获取用户ID:

$user->save();
$user_id = $user->id