2012-09-22 69 views
0

我嘗試在我的數據庫中獲取用戶的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屬性在同一時間,並沒有太多工作...

還有就是我的DB:http://pastebin.com/u5CNKj9M

謝謝您的幫助!

回答

4

print_r($profile->getErrors());

(更新)爲了保存後獲取用戶ID:

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

謝謝! 如何在保存() –

+2

@Mike Boutin後從我的$ user模型中獲得AutoIncremented ID:請參閱我的更新 – Ozerich

+1

非常感謝!我很喜歡yii,你在這裏幫了我很多! –