Symfony2类Brenne \ BaseBundle \ Entity \ Websites不是有效实体或映射超类

时间:2014-01-29 20:15:02

标签: php symfony doctrine

我确实有一个非常奇怪的问题并且搜索并尝试了不同的方法。正如我的标题所述,我的实体(包括所有实体!)都不起作用 - 意味着它们无法映射。

我很快就到了这一点:

扩展阵列

Array ( [0] => Core [1] => date [2] => ereg [3] => libxml [4] => openssl [5] => pcre [6] => sqlite3 [7] => zlib [8] => bcmath [9] => bz2 [10] => calendar [11] => ctype [12] => curl [13] => dba [14] => dom [15] => hash [16] => fileinfo [17] => filter [18] => ftp [19] => gd [20] => gettext [21] => gmp [22] => SPL [23] => iconv [24] => session [25] => intl [26] => json [27] => ldap [28] => mbstring [29] => mcrypt [30] => mssql [31] => mysql [32] => standard [33] => PDO [34] => pdo_dblib [35] => mysqlnd [36] => pdo_sqlite [37] => pgsql [38] => apc [39] => posix [40] => Reflection [41] => imap [42] => shmop [43] => SimpleXML [44] => snmp [45] => soap [46] => sockets [47] => pdo_mysql [48] => exif [49] => sysvmsg [50] => sysvsem [51] => sysvshm [52] => tidy [53] => tokenizer [54] => wddx [55] => xml [56] => xmlreader [57] => xmlrpc [58] => xmlwriter [59] => xsl [60] => zip [61] => mysqli [62] => apache2handler [63] => Phar [64] => mhash )

到目前为止,我提出并尝试修复:

  1. APC on(没有eAcc导致问题)REF:("Class XXX is not a valid entity or mapped super class" after moving the class in the filesystem
  2. 删除参考资料中的Doctrine文件夹,清除缓存。没有成功。
  3. 将完整的命名空间添加到配置ORM的实体//更改:“company”到“x / basebundle / entity / company”不起作用,因此还原了更改。
  4. 我不使用annoations,Iam使用yml。
  5. 自动映射是真的!
  6. Resources/Config/Doctrine/Websites.orm.yml将实体类作为第一个参数:

    Brenne\BaseBundle\Entity\Website:
        type: entity
        table: website
        repositoryClass: Brenne\BaseBundle\Repository\WebsiteRepository
        id:
            id:
                type: integer
                generator: { strategy: AUTO }
        fields:
            name:
                type: string
                length: 110
                nullable: true
            url:
                type: string
                length: 255
                nullable: true
            logo:
                type: string
                length: 255
                nullable: true
            description:
                type: text
        oneToMany:
            assignedPing:
                targetEntity: ping
                mappedBy: website
        manyToOne:
            company:
              targetEntity: Company
              inversedBy: website
    

    /Entity/Websites.orm.yml将实体类作为第一个参数:

    <?php
    
    namespace Brenne\BaseBundle\Entity;
    
    use Doctrine\ORM\Mapping as ORM;
    
    /**
     * Website
     */
    class Website
    {
        /**
         * @var integer
         */
        private $id;
    
        /**
         * @var string
         */
        private $name;
    
        /**
         * @var string
         */
        private $url;
    
        /**
         * @var string
         */
        private $logo;
    
        /**
         * @var string
         */
        private $description;
    
        /**
         * @var \Doctrine\Common\Collections\Collection
         */
        private $assignedPing;
    
        /**
         * @var \Brenne\BaseBundle\Entity\Company
         */
        private $company;
    
        /**
         * Constructor
         */
        public function __construct()
        {
            $this->assignedPing = new \Doctrine\Common\Collections\ArrayCollection();
        }
    
        /**
         * Get id
         *
         * @return integer 
         */
        public function getId()
        {
            return $this->id;
        }
    
        /**
         * Set name
         *
         * @param string $name
         * @return Website
         */
        public function setName($name)
        {
            $this->name = $name;
    
            return $this;
        }
    
        /**
         * Get name
         *
         * @return string 
         */
        public function getName()
        {
            return $this->name;
        }
    
        /**
         * Set url
         *
         * @param string $url
         * @return Website
         */
        public function setUrl($url)
        {
            $this->url = $url;
    
            return $this;
        }
    
        /**
         * Get url
         *
         * @return string 
         */
        public function getUrl()
        {
            return $this->url;
        }
    
        /**
         * Set logo
         *
         * @param string $logo
         * @return Website
         */
        public function setLogo($logo)
        {
            $this->logo = $logo;
    
            return $this;
        }
    
        /**
         * Get logo
         *
         * @return string 
         */
        public function getLogo()
        {
            return $this->logo;
        }
    
        /**
         * Set description
         *
         * @param string $description
         * @return Website
         */
        public function setDescription($description)
        {
            $this->description = $description;
    
            return $this;
        }
    
        /**
         * Get description
         *
         * @return string 
         */
        public function getDescription()
        {
            return $this->description;
        }
    
        /**
         * Add assignedPing
         *
         * @param \Brenne\BaseBundle\Entity\ping $assignedPing
         * @return Website
         */
        public function addAssignedPing(\Brenne\BaseBundle\Entity\ping $assignedPing)
        {
            $this->assignedPing[] = $assignedPing;
    
            return $this;
        }
    
        /**
         * Remove assignedPing
         *
         * @param \Brenne\BaseBundle\Entity\ping $assignedPing
         */
        public function removeAssignedPing(\Brenne\BaseBundle\Entity\ping $assignedPing)
        {
            $this->assignedPing->removeElement($assignedPing);
        }
    
        /**
         * Get assignedPing
         *
         * @return \Doctrine\Common\Collections\Collection 
         */
        public function getAssignedPing()
        {
            return $this->assignedPing;
        }
    
        /**
         * Set company
         *
         * @param \Brenne\BaseBundle\Entity\Company $company
         * @return Website
         */
        public function setCompany(\Brenne\BaseBundle\Entity\Company $company = null)
        {
            $this->company = $company;
    
            return $this;
        }
    
        /**
         * Get company
         *
         * @return \Brenne\BaseBundle\Entity\Company 
         */
        public function getCompany()
        {
            return $this->company;
        }
    }
    

    我不知道还有什么可做的,请你提出一个想法!谢谢你的时间。

3 个答案:

答案 0 :(得分:2)

您必须命名存储它们的映射文件和文件夹 根据惯例完全

...否则,在加载文件时,您将面临无效的映射classmetadata或错误。

请注意,某些系统上的文件和文件夹区分大小写

<强>解决方案:

应该读取映射文件:

  • Website.orm.yml
  • ......或......
  • Brenne.BaseBundle.Entity.Website.orm.yml

它应该存在于文件夹中......

src/Brenne/BaseBundle/Resources/config/doctrine

请注意命名(configdoctrine - 小型上限,Website没有 s )......


清除symfony缓存以获取正确的环境(app/console ca:c --env=..rm -rf app/cache/*)并重新启动您的webserver / fpm-pool(以便从APC和opcache中清除缓存的元数据)

答案 1 :(得分:0)

尝试在命名空间前使用\

\Brenne\BaseBundle\Entity\Websites:
type: entity
table: websites
repositoryClass: \Brenne\BaseBundle\Repository\WebsitesRepository

答案 2 :(得分:0)

如果确实您的Websites.orm.yml文件的内容,则缩进错误:

您应该在Brenne\BaseBundle\Entity\Websites:之后缩进:

Brenne\BaseBundle\Entity\Websites:
    type: entity
    table: websites
    repositoryClass: Brenne\BaseBundle\Repository\WebsitesRepository
    id:
        id:
            type: integer
            generator: { strategy: AUTO }
    fields:
        name:
            type: string
            length: 110
            nullable: true
        url:
            type: string
            length: 255
            nullable: true
        url:
            type: string
            length: 255
            nullable: true
        description:
            type: text
    manyToOne:
        company:
            targetEntity: Company
            inversedBy: websites
            joinColumn:
                name: company_id
                referencedCo