0

symfony2 で FOSUserBundle を使用していますが、非常にうまく機能しますが、たとえば Entry のようなフィールドを持つ別のテーブルを作成する必要があります。

 user_id, description,...

userテーブルとテーブルの間に関係を作る必要がありEntryます。1 対多の関係を構築するための最良の方法は何ですか? どのクラスを拡張する必要がありますか?

次のエラーが表示されます。

Entry has no association named ApplicationSonataUserBundle:User

私のコードは次のとおりです。

   /**
 *
 * @ORM\ManyToOne(targetEntity="\Application\Sonata\UserBundle\Entity\User",  inversedBy="entry")
 * @ORM\JoinColumn(name="user_id", referencedColumnName="id")
*/

protected $users;

私はこの指示を使用します:

   $em = $this->getDoctrine()->getEntityManager();
$query = $em->createQuery('SELECT b
                               FROM LoggerFrontendBundle:Entry a JOIN a.ApplicationSonataUserBundle:User b
                       ') ;

ありがとう

4

1 に答える 1

0

ユーザー エンティティ:

/**
* @ORM\OneToOne(targetEntity="path to new Entity", mappedBy="user", cascade={"persist"})
*/
protected $name;

新しいエンティティ:

/**
* @ORM\OneToOne(targetEntity="path to User Entity", inversedBy="name")
*/
protected $user;

コントローラーから

$em = $this->getDoctrine()->getEntityManager();
// when you query users, you get the information from the new Entity.
$users = $em->getRepository('ApplicationSonataUserBundle:User')->findAll();

return array('users' => $user); // return the array of user information

小枝:

{% for user in users %} // loop through users<br/>

{{ user.name.getName }} // you can call user.getname or user.getEmail , you can add the name from the Entity on and get the fields from the new Entity like user.name.getName etc...

{% endfor %} //end loop
于 2012-02-16T03:38:25.833 に答える