在symfony2中找不到存储库实体

时间:2015-03-17 15:29:44

标签: php symfony doctrine-orm

我正在使用Symfony2开发两个项目,我开始编写第二个项目的代码,我在自定义函数中面临一些问题,无法在我的表格中进行搜索。

这是我的网站实体

namespace Ad\SisBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * Sites
 *
 * @ORM\Table(name="sites")
 * @ORM\Entity(repositoryClass="Ad\SisBundle\Entity\SitesRepository")
 */
class Sites
{

这是我的SitesRepository实体

namespace Ad\SisBundle\Entity;

use Doctrine\ORM\EntityRepository;

class SitesRepository extends EntityRepository
{

问题是我无法访问我在SitesRepository中创建的任何功能

我正在转储Doctrine EntityRepository Class,我看到了这个。

EntityRepository {#309 ▼
  #_entityName: "Ad\SisBundle\Entity\Sites"
  #_em: EntityManager {#289 …10}
  #_class: ClassMetadata {#298 ▼
    +name: "Ad\SisBundle\Entity\Sites"
    +namespace: "Ad\SisBundle\Entity"
    +rootEntityName: "Ad\SisBundle\Entity\Sites"
    +customGeneratorDefinition: null
    +customRepositoryClassName: null
    +isMappedSuperclass: false
    +parentClasses: []
    +subClasses: []
    +namedQueries: []
    +namedNativeQueries: []
    +sqlResultSetMappings: []
    +identifier: array:1 [▶]
    +inheritanceType: 1
    +generatorType: 4
    +fieldMappings: array:5 [▶]
    +fieldNames: array:5 [▶]
    +columnNames: array:5 [▶]
    +discriminatorValue: null
    +discriminatorMap: []
    +discriminatorColumn: null
    +table: array:1 [▶]
    +lifecycleCallbacks: []
    +entityListeners: []
    +associationMappings: []
    +isIdentifierComposite: false
    +containsForeignIdentifier: false
    +idGenerator: IdentityGenerator {#306 ▶}
    +sequenceGeneratorDefinition: null
    +tableGeneratorDefinition: null
    +changeTrackingPolicy: 1
    +isVersioned: null
    +versionField: null
    +reflClass: ReflectionClass {#307 ▶}
    +isReadOnly: false
    #namingStrategy: DefaultNamingStrategy {#276}
    +reflFields: array:5 [▶]
    -_prototype: null
  }
}

所以我去了我的第一个项目,这项工作非常完美,也做了同样的事情。

ScheduleRepository {#1931 ▼
  #_entityName: "ApplicationBundle\Entity\Schedule"
  #_em: EntityManager {#137 …10}
  #_class: ClassMetadata {#1825 ▼
    +name: "ApplicationBundle\Entity\Schedule"
    +namespace: "ApplicationBundle\Entity"
    +rootEntityName: "ApplicationBundle\Entity\Schedule"
    +customGeneratorDefinition: null
    +customRepositoryClassName: "ApplicationBundle\Entity\ScheduleRepository"
    +isMappedSuperclass: false
    +parentClasses: []
    +subClasses: []
    +namedQueries: []
    +namedNativeQueries: []
    +sqlResultSetMappings: []
    +identifier: array:1 [▶]
    +inheritanceType: 1
    +generatorType: 4
    +fieldMappings: array:3 [▶]
    +fieldNames: array:3 [▶]
    +columnNames: array:3 [▶]
    +discriminatorValue: null
    +discriminatorMap: []
    +discriminatorColumn: null
    +table: array:2 [▶]
    +lifecycleCallbacks: array:2 [▶]
    +entityListeners: []
    +associationMappings: array:2 [▶]
    +isIdentifierComposite: false
    +containsForeignIdentifier: false
    +idGenerator: IdentityGenerator {#1852 ▶}
    +sequenceGeneratorDefinition: null
    +tableGeneratorDefinition: null
    +changeTrackingPolicy: 1
    +isVersioned: null
    +versionField: null
    +reflClass: ReflectionClass {#1840 ▶}
    +isReadOnly: false
    #namingStrategy: DefaultNamingStrategy {#119}
    +reflFields: array:5 [▶]
    -_prototype: null
  }
}

在我的项目#1的计划实体中,我填充了 customRepositoryClassName ,但在我的网站实体中没有。为什么?两者都使用相同版本的教义和symfony。


我看到项目#1中的转储正在转储 ScheduleRepository ,而项目#2正在转储 EntityRepository 。也许这就是问题?

项目#1转储:

$em = $this->getDoctrine()->getManager();
dump( $em->getRepository( "ApplicationBundle:Schedule" ) );exit;

Project#2转储:

$em = $this->getDoctrine()->getManager();
dump( $em->getRepository( "AdSisBundle:Sites" ) );exit;

项目#2中的实体是使用:http://symfony.com/doc/current/cookbook/doctrine/reverse_engineering.html

创建的

这是两个项目之间的唯一区别。

感谢您的帮助。

0 个答案:

没有答案