无法将表映射到Symfony - Doctrine实体。找不到该文件但该类不在其中,类名或命名空间可能有拼写错误

时间:2015-03-12 13:19:36

标签: php mysql symfony doctrine-orm

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

  

C:\ XAMPP \ htdocs中\ goodstuff \ SRC \的appbundle \实体\ 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

1 个答案:

答案 0 :(得分:3)

仅使用您的包名称进行尝试。那会有用吗?

php app/console doctrine:generate:entities AppBundle

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

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