2011-10-28 42 views
4

FOSUserBundle工作好,我工作的項目。但我試圖嵌入FOSFacebookBundle並使其與FOSUserBundle一起使用。FOSUserBundle和FOSFacebookBundle:userManager-> UpdateUser兩個(): 「未知錯誤」(這是一個錯誤的學說)

在此目的下,我建立了自己的Acme\MyBundle\Entity\User.php來添加一些我想從Facebook存儲的字段以及提供UserBundle的字段。這個類的代碼 已被調試並運行(呃...這就是我想的!見下文)。

什麼不工作是(在我Acme\MyBundle\Security\User\Provider\FacebookProvider.php,在loadUserByUsername()內)這一行:

 $this->userManager->updateUser($user); 

Acme\MyBundle\Security\User\Provider\FacebookProvider.php相同的文檔(read it here

以下元素是print_r($user);的輸出,正好在執行$this->userManager->updateUser($user);的 之前:

 
Acme\MyBundle\Entity\User Object 
(
    [id:protected] => 
    [facebookID:protected] => 847000001 
    [first_name:protected] => Peter 
    [middle_name:protected] => 
    [last_name:protected] => Parker 
    [fullname:protected] => Peter Parker 
    [locale:protected] => en_US 
    [timezone:protected] => 2 
    [updated_time:protected] => 2011-10-27T17:13:24+0000 
    [birthday:protected] => DateTime Object 
     (
      [date] => 1961-07-01 10:31:53 
      [timezone_type] => 3 
      [timezone] => Europe/Berlin 
     ) 
    [languages:protected] => Doctrine\Common\Collections\ArrayCollection Object 
     (
     [_elements:Doctrine\Common\Collections\ArrayCollection:private] => Array 
      (
     [0] => Acme\MyBundle\Entity\SpokenLanguage Object 
      (
      [facebookID:Acme\MyBundle\Entity\SpokenLanguage:private] => 113051505375958 
      [name:Acme\MyBundle\Entity\SpokenLanguage:private] => Italien 
      ) 
     [1] => Acme\MyBundle\Entity\SpokenLanguage Object 
      (
      [facebookID:Acme\MyBundle\Entity\SpokenLanguage:private] => 112264595467201 
      [name:Acme\MyBundle\Entity\SpokenLanguage:private] => Français 
      ) 
     [2] => Acme\MyBundle\Entity\SpokenLanguage Object 
      (
      [facebookID:Acme\MyBundle\Entity\SpokenLanguage:private] => 103803232991647 
      [name:Acme\MyBundle\Entity\SpokenLanguage:private] => English 
      ) 
     ) 
    ) 
    [usernameFB:protected] => spiderman 
    [username:protected] => Peter Parker 
    [usernameCanonical:protected] => 
    [email:protected] => [email protected] 
    [emailCanonical:protected] => 
    [enabled:protected] => 1 
    [algorithm:protected] => 
    [salt:protected] => 
    [password:protected] => 
    [plainPassword:protected] => 
    [lastLogin:protected] => 
    [confirmationToken:protected] => 540grdgfg343004g8g0skg0wg408k 
    [passwordRequestedAt:protected] => 
    [groups:protected] => 
    [locked:protected] => 
    [expired:protected] => 
    [expiresAt:protected] => 
    [roles:protected] => Array 
     (
      [0] => ROLE_FACEBOOK 
     ) 

    [credentialsExpired:protected] => 
    [credentialsExpireAt:protected] => 
) 

消息錯誤是「UNKNOWN ERROR」。所以我決定去看這個消息在Bundle中發送的位置。我發現它被設置爲一個例外。我決定輸出異常消息。

所以下面的異常消息:

一個新的實體是通過關係 「的Acme \ MyBundle \實體\用戶#語言」中沒有配置到 級聯持續經營的實體發現: 阿克米\ MyBundle \實體\ SpokenLanguage @ 000000004a9e2dfa0000000001482b74。 明確地堅持新的實體或配置級聯堅持 操作的關係。如果找不到哪個實體 導致問題實現 'Acme \ MyBundle \ Entity \ SpokenLanguage #__ toString()'以獲取線索。

所以我想我沒有很好地編碼我的User類的Doctrine Annotations,問題是ManyToMany()關聯映射。

這裏領域$語言的註釋中我Acme\MyBundle\Entity\User.php

/** 
* @var \Doctrine\Common\Collections\ArrayCollection 
* @ORM\ManyToMany(targetEntity="SpokenLanguage") 
* @ORM\JoinTable(name="users_spokenlanguage", 
*  joinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id")}, 
*  inverseJoinColumns={@ORM\JoinColumn(name="spokenlanguage_id", referencedColumnName="facebookID")} 
*  ) 
*/ 
protected $languages; 

難道你們有什麼想法沒有如何解決這個問題呢? 我在考慮一個級聯問題。

謝謝大家。

+0

好呀!我已經解決了這個問題......最後,你必須在Annotation ManyToMany中添加參數'cascade = {'persist','remove','merge'}'。 像這樣: '@ORM \ ManyToMany(targetEntity =「SpokenLanguage」,cascade = {「persist」,「remove」,「merge」})' – ohFRY

+0

請發表您的評論作爲回答並接受它;) –

回答

2

OKAY!我終於解決了這個問題!

您必須將參數cascade={'persist','remove','merge'}添加到Annotation ManyToMany。

像這樣:

@ORM\ManyToMany(targetEntity="SpokenLanguage", cascade={"persist", "remove", "merge"})