3

我正在将应用程序从 Symfony 2.0 升级到 Symfony 2.1,我遵循了这个升级文件并且一切正常,除了cache:clear在使用某些存储库时出现错误之后。这是错误:

[Semantical Error] The annotation "@ORM\Table" in class 
edasiclinic\AlertesBundle\Repository\AlertesRepository was never imported. Did you maybe
forget to add a "use" statement for this annotation?

这是一个示例,我在其他存储库中遇到此错误。@ORM\Table如果我不在那里使用注释,我不明白为什么我必须在存储库文件中导入。

另外,如果我等待约 10 秒,然后刷新浏览器,它就可以工作......

编辑

这是实体:

<?php

namespace edasiclinic\DatabaseBundle\Entity;

use Doctrine\ORM\Mapping as ORM;


/**
 * edasiclinic\DatabaseBundle\Entity\Alertes
 *
 * @ORM\Table(name="alertes")
 * @ORM\Entity(repositoryClass="edasiclinic\AlertesBundle\Repository\AlertesRepository")
 * @ORM\HasLifecycleCallbacks()
 */
class Alertes
{
    /**
     * @var integer $id
     *
     * @ORM\Id
     * @ORM\Column(name="idAlerta", type="integer")
     * @ORM\GeneratedValue(strategy="IDENTITY")
     */
    private $id;

    ...
}

这是存储库类:

<?php

namespace edasiclinic\AlertesBundle\Repository;

use Doctrine\ORM\EntityRepository;
use edasiclinic\DasiBundle\Funcions\AES;


class AlertesRepository extends EntityRepository
{

    public function countUnread($user, $idioma, $fus)
    {
        // ...
    }
}

谢谢

4

4 回答 4

3

我今天遇到了同样的问题。经过一番谷歌搜索后,解决方案显然是在 Repository 类定义之前包含一个注释块。

在你的情况下:

/**
 * 警报存储库
 */
类 AlertesRepository 扩展了 EntityRepository
{
  ...
}

如果没有该注释块,您将收到有关“@ORM\Table”的无意义错误。又一个 Symfony/Doctrine 怪事>_>

于 2013-08-21T17:47:41.253 回答
1

看起来你忘记添加use语句了。

<?php

namespace Acme\MyBundle\Entity;

// Remember to include this use statement
use Doctrine\ORM\Mapping as ORM;

/**
 * My Entity
 *
 * @ORM\Table()
 * @ORM\Entity(repositoryClass="Acme\MyBundle\Entity\MyEntityRepository")
 */
class MyEntity
{
}
于 2013-07-10T02:16:59.480 回答
1

这是 5.3.8 之前版本中的一个 PHP 错误。从symfony 系统要求

$this->addRecommendation(
    version_compare($installedPhpVersion, '5.3.8', '>='),
    'When using annotations you should have at least PHP 5.3.8 due to PHP bug #55156',
    'Install PHP 5.3.8 or newer if your project uses annotations.'
);

如果您无法升级到 PHP 版本 >= 5.3.8,请参阅PHP 错误 #55156了解更多详细信息和可能的解决方法。

于 2013-09-26T18:56:52.130 回答
0

对我来说,它只适用于某些版本的 PHP,解决方案是将 Repository 类放在实体类文件夹上方的文件夹中

于 2013-08-23T06:57:17.867 回答