【问题标题】:entity class is not getting recognize ! why?实体类没有得到认可!为什么?
【发布时间】:2015-08-04 07:55:39
【问题描述】:

当我尝试使用我的实体类时,它会返回一个错误,例如 所以:

尝试从命名空间“MyBundle\Entity”加载类“test_class”。

您是否忘记了另一个命名空间的“使用”语句?

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\DependencyInjection\ContainerAware;
use MyBundle\Entity\test_class;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;

所以当我尝试像这样使用我的实体类时,它总是返回那个错误。

但是当我单击“test_class()”时,它会打开 test_class.php 文件。

这意味着命名空间是正确的。

  $tst = new test_class();

这是我的实体类 --

namespace MyBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * test_class
 *
 * @ORM\Table()
 * @ORM\Entity
 */
class test_class{ ....

有谁知道如何解决这个问题?

提前致谢。

【问题讨论】:

  • 你必须用大写来命名你的类。文件名应该是TestClass.php,类名应该是TestClass,而不是test_class。
  • @MeuhMeuh 非常感谢,我现在就试试...

标签: php symfony doctrine-orm entity


【解决方案1】:

@MeuhMeuh(上面的 cmets)是对的。为了格式化,我只是将其发布为答案。

命名类时应遵循PascalCasing 约定。没有人会强迫你,但这是个好习惯。

另一方面,在类名中包含_ 特别糟糕,因为根据 PSR-0 标准,它被解释为 DIRECTORY_SEPARATOR (source)

【讨论】:

    猜你喜欢
    • 2023-03-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-19
    相关资源
    最近更新 更多