【问题标题】:Can't map table to Symfony - Doctrine entity. The file was not found but the class was not in it, the class name or namespace probably has a typo无法将表映射到 Symfony - Doctrine 实体。找不到文件但类不在其中,类名或命名空间可能有错字
【发布时间】:2015-03-12 13:19:35
【问题描述】:

我正在尝试遵循 Symfony 官方手册(只是表的名称不同)并希望将我的数据库表与实体映射。我创建了一个基于(复制/粘贴 URL 和文件名,所以拼写错误)的类:

C:\xampp\htdocs\goodstuff\src\AppBundle\Entity\Customer.php

类文件源代码:

namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 * @ORM\Table(name="customer")
 */
class Customer
{
        /**
     * @ORM\Column(type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;
    /**
     * @ORM\Column(type="string", length=255)
     */ 
    protected $first_name;
    /**
     * @ORM\Column(type="string", length=255)
     */     
    protected $last_name;
    /**
     * @ORM\Column(type="string", length=255)
     */     
    protected $mid_name;
    /**
     * @ORM\Column(type="string", length=100)
     */     
    protected $phone;
    /**
     * @ORM\Column(type="string", length=100)
     */     
    protected $email;
    /**
     * @ORM\Column(type="string", length=1000)
     */     
    protected $comments;

}

然后我运行命令:

c:\xampp\htdocs\goodstuff>....\php\php app\console octrine:generate:entities AppBundle/Entity/Customer

c:\xampp\htdocs\goodstuff>....\php\php app\console octrine:generate:entities AppBundle\Entity\Customer

在这两种情况下,我都会收到相同的错误消息:

c:\xampp\htdocs\goodstuff>..\..\php\php app\console doctrine:generate:entities AppBundle/Entity/Customer

namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 * @ORM\Table(name="customer")
 */
class Customer
{
            /**
     * @ORM\Column(type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
        protected $id;
    /**
     * @ORM\Column(type="string", length=255)
     */
        protected $first_name;
    /**
     * @ORM\Column(type="string", length=255)
     */
        protected $last_name;
    /**
     * @ORM\Column(type="string", length=255)
     */
        protected $mid_name;
    /**
     * @ORM\Column(type="string", length=100)
     */
        protected $phone;
    /**
     * @ORM\Column(type="string", length=100)
     */
        protected $email;
    /**
     * @ORM\Column(type="string", length=1000)
     */
        protected $comments;

}




  [RuntimeException]
  The autoloader expected class "AppBundle\Entity\Customer" to be defined in file "C:\xampp\htdocs\goodstuff/src\AppBundle\Entity\Customer.php". The file was found but the class was not in it, the class name or namespace probab  ly has a typo.



doctrine:generate:entities [--path="..."] [--no-backup] name

【问题讨论】:

  • 你能用缺少的错误信息编辑你的问题吗?
  • @Veve 我已经修改了

标签: php mysql symfony doctrine-orm


【解决方案1】:

仅使用您的捆绑包名称进行尝试。那么它会起作用吗?

php app/console doctrine:generate:entities AppBundle

或者尝试使用 --path 属性,如语法所述:

doctrine:generate:entities [--path="..."] [--no-backup] name

【讨论】:

  • 1) 捆绑“AppBundle”不包含任何映射实体。 2)路径是说“没有足够的论据。”
  • 您的实体的确切命名空间是什么?真的是 /src/AppBundle/Entity 吗?
  • 实际创建的实体,但不是来自现有类,但首先我确实生成:实体,然后生成:实体...
  • 您是否对不必使用生成命令这一事实感到担忧?您应该能够使用手动编码的实体。我什至不再为此烦恼。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多