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


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手册(只是表的名称不同),并希望将我的数据库表与实体映射。我创建了一个基于(复制/粘贴 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

只使用您的捆绑包名称进行尝试。那行得通吗?

php app/console doctrine:generate:entities AppBundle

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

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