是否可以通过注释在targetEntity中使用相对路径


Is it possible to use relative paths in targetEntity through annotations?

我在谷歌上搜索了这些信息,但没有得到答案。我想做的是用一个相对路径设置targetEntity,这可能吗?

这里有一个例子:

AppBundle
|
|-Entity
  |-User.php
  |-OAuth
    |-Client.php
    |-AccessToken.php

AccessToken.php

Class AccessToken
{
  /**
   * @ORM'ManyToOne(targetEntity="Client")
   */
  protected $client;
  /**
   * @ORM'ManyToOne(targetEntity="..'User")
   */
  protected $user;

targetEntity="Client"工作是因为它在同一个命名空间中,但targetEntity="..'User"不工作。我知道targetEntity="AppBundle'Entity'User"有效,但我想使用相对路径。

谢谢。

不,这是不可能的。

传递给targetEntity的是一个名称空间,而不是路径。您可以只在两个实体都在同一命名空间中时传递类名(选项1),也可以传递完整命名空间(选项2):

选项1:

targetEntity="Client"

选项2:

targetEntity="AppBundle'Entity'User"