Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/262.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Zend 2&x2B;实体请求原则_Php_Zend Framework2_Doctrine - Fatal编程技术网

Php Zend 2&x2B;实体请求原则

Php Zend 2&x2B;实体请求原则,php,zend-framework2,doctrine,Php,Zend Framework2,Doctrine,我在使用教义方面有困难。当我尝试获取特定实体时,无法检索结果。 我有这些实体: <?php namespace TDS\Entity; use Doctrine\ORM\Mapping as ORM; /** * Courses * * @ORM\Table(name="courses") * @ORM\Entity */ class Courses { /** * @var integer * * @ORM\Column(name="

我在使用教义方面有困难。当我尝试获取特定实体时,无法检索结果。 我有这些实体:

<?php

namespace TDS\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * Courses
 *
 * @ORM\Table(name="courses")
 * @ORM\Entity
 */
class Courses
{
    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer", nullable=false)
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="IDENTITY")
     */
    private $id;

    /**
     * @var string
     *
     * @ORM\Column(name="name", type="string", length=64, nullable=false)
     */
    private $name;



    /**
     * Get id
     *
     * @return integer
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set name
     *
     * @param string $name
     *
     * @return Courses
     */
    public function setName($name)
    {
        $this->name = $name;

        return $this;
    }

    /**
     * Get name
     *
     * @return string
     */
    public function getName()
    {
        return $this->name;
    }
}
以下是我提出请求的方式:

$qb = $this->getEm()->createQueryBuilder();
$qb->select('clp')->from('TDS\Entity\CoursesLevelsPlaces', 'clp');
$list = $qb->getQuery()->getResult();
问题是我无法检索我的实体。例如,如果我对课程提出请求,结果将正确显示。 每个CoursesLevelsPlaces行都是唯一的,并且与其他实体具有一对一的关系

作为参考,我从数据库模式中生成了这些实体(反向原则)

你知道我为什么会得到这个结果吗?
谢谢

您不应该
打印\u r
var\u dump
完整的原则2实体,因为所有元数据等也将被打印。这将导致内存问题,并且输出将对您的浏览器显示太多

你有几个选择

  • 只需遍历结果并使用getter检索数据

    foreach ($list as $entity) {
        echo $entity->getId() . PHP_EOL;
    }
    
  • 使用原则中的调试util

    foreach ($list as $entity) {
        Doctrine\Common\Util\Debug::dump($entity);
    }
    
  • 使用调试器(xdebug)并在IDE中放置断点,然后观察实体内容


谢谢,就这样。我没有想到这一点。
<?php

namespace TDS\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * CoursesLevelsPlaces
 *
 * @ORM\Table(name="courses_levels_places", uniqueConstraints={@ORM\UniqueConstraint(name="id_course", columns={"id_course", "id_level", "id_place", "id_time_slot"})}, indexes={@ORM\Index(name="courses", columns={"id_course"}), @ORM\Index(name="levels", columns={"id_level"}), @ORM\Index(name="places", columns={"id_place"}), @ORM\Index(name="time_slot", columns={"id_time_slot"})})
 * @ORM\Entity
 */
class CoursesLevelsPlaces
{
    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer", nullable=false)
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="IDENTITY")
     */
    private $id;

    /**
     * @var \TDS\Entity\Courses
     *
     * @ORM\ManyToOne(targetEntity="TDS\Entity\Courses")
     * @ORM\JoinColumns({
     *   @ORM\JoinColumn(name="id_course", referencedColumnName="id")
     * })
     */
    private $idCourse;

    /**
     * @var \TDS\Entity\Levels
     *
     * @ORM\ManyToOne(targetEntity="TDS\Entity\Levels")
     * @ORM\JoinColumns({
     *   @ORM\JoinColumn(name="id_level", referencedColumnName="id")
     * })
     */
    private $idLevel;

    /**
     * @var \TDS\Entity\Places
     *
     * @ORM\ManyToOne(targetEntity="TDS\Entity\Places")
     * @ORM\JoinColumns({
     *   @ORM\JoinColumn(name="id_place", referencedColumnName="id")
     * })
     */
    private $idPlace;

    /**
     * @var \TDS\Entity\TimeSlot
     *
     * @ORM\ManyToOne(targetEntity="TDS\Entity\TimeSlot")
     * @ORM\JoinColumns({
     *   @ORM\JoinColumn(name="id_time_slot", referencedColumnName="id")
     * })
     */
    private $idTimeSlot;



    /**
     * Get id
     *
     * @return integer
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set idCourse
     *
     * @param \TDS\Entity\Courses $idCourse
     *
     * @return CoursesLevelsPlaces
     */
    public function setIdCourse(\TDS\Entity\Courses $idCourse = null)
    {
        $this->idCourse = $idCourse;

        return $this;
    }

    /**
     * Get idCourse
     *
     * @return \TDS\Entity\Courses
     */
    public function getIdCourse()
    {
        return $this->idCourse;
    }

    /**
     * Set idLevel
     *
     * @param \TDS\Entity\Levels $idLevel
     *
     * @return CoursesLevelsPlaces
     */
    public function setIdLevel(\TDS\Entity\Levels $idLevel = null)
    {
        $this->idLevel = $idLevel;

        return $this;
    }

    /**
     * Get idLevel
     *
     * @return \TDS\Entity\Levels
     */
    public function getIdLevel()
    {
        return $this->idLevel;
    }

    /**
     * Set idPlace
     *
     * @param \TDS\Entity\Places $idPlace
     *
     * @return CoursesLevelsPlaces
     */
    public function setIdPlace(\TDS\Entity\Places $idPlace = null)
    {
        $this->idPlace = $idPlace;

        return $this;
    }

    /**
     * Get idPlace
     *
     * @return \TDS\Entity\Places
     */
    public function getIdPlace()
    {
        return $this->idPlace;
    }

    /**
     * Set idTimeSlot
     *
     * @param \TDS\Entity\TimeSlot $idTimeSlot
     *
     * @return CoursesLevelsPlaces
     */
    public function setIdTimeSlot(\TDS\Entity\TimeSlot $idTimeSlot = null)
    {
        $this->idTimeSlot = $idTimeSlot;

        return $this;
    }

    /**
     * Get idTimeSlot
     *
     * @return \TDS\Entity\TimeSlot
     */
    public function getIdTimeSlot()
    {
        return $this->idTimeSlot;
    }
}
Array ( [0] => TDS\Entity\CoursesLevelsPlaces Object ( [id:TDS\Entity\CoursesLevelsPlaces:private] => 1 [idCourse:TDS\Entity\CoursesLevelsPlaces:private] => DoctrineORMModule\Proxy\__CG__\TDS\Entity\Courses Object ( [__initializer__] => Closure Object ( [static] => Array ( [entityPersister] => Doctrine\ORM\Persisters\Entity\BasicEntityPersister Object ( [class:protected] => Doctrine\ORM\Mapping\ClassMetadata Object ( [name] => TDS\Entity\Courses [namespace] => TDS\Entity [rootEntityName] => TDS\Entity\Courses [customGeneratorDefinition] => [customRepositoryClassName] => [isMappedSuperclass] => [isEmbeddedClass] => [parentClasses] => Array ( ) [subClasses] => Array ( ) [embeddedClasses] => Array ( ) [namedQueries] => Array ( ) [namedNativeQueries] => Array ( ) [sqlResultSetMappings] => Array ( ) [identifier] => Array ( [0] => id ) [inheritanceType] => 1 [generatorType] => 4 [fieldMappings] => Array ( [id] => Array ( [fieldName] => id [type] => integer [scale] => 0 [length] => [unique] => [nullable] => [precision] => 0 [columnName] => id [id] => 1 ) [name] => Array ( [fieldName] => name [type] => string [scale] => 0 [length] => 64 [unique] => [nullable] => [precision] => 0 [columnName] => name ) ) [fieldNames] => Array ( [id] => id [name] => name ) [columnNames] => Array ( [id] => id [name] => name ) [discriminatorValue] => [discriminatorMap] => Array ( ) [discriminatorColumn] => [table] => Array ( [name] => courses ) [lifecycleCallbacks] => Array ( ) [entityListeners] => Array ( ) [associationMappings] => Array ( ) [isIdentifierComposite] => [containsForeignIdentifier] => [idGenerator] => Doctrine\ORM\Id\IdentityGenerator Object ( [sequenceName:Doctrine\ORM\Id\IdentityGenerator:private] => ) [sequenceGeneratorDefinition] => [tableGeneratorDefinition] => [changeTrackingPolicy] => 1 [isVersioned] => [versionField] => [cache] => [reflClass] => ReflectionClass Object ( [name] => TDS\Entity\Courses ) [isReadOnly] => [namingStrategy:protected] => Doctrine\ORM\Mapping\DefaultNamingStrategy Object ( ) [reflFields] => Array ( [id] => ReflectionProperty Object ( [name] => id [class] => TDS\Entity\Courses ) [name] => ReflectionProperty Object ( [name] => name [class] => TDS\Entity\Courses ) ) [instantiator:Doctrine\ORM\Mapping\ClassMetadataInfo:private] => Doctrine\Instantiator\Instantiator Object ( ) ) [conn:protected] => Doctrine\DBAL\Connection Object ( [_conn:protected] => Doctrine\DBAL\Driver\PDOConnection Object ( ) [_config:protected] => Doctrine\ORM\Configuration Object ( [_attributes:protected] => Array ( [autoGenerateProxyClasses] => 1 [proxyDir] => data/DoctrineORMModule/Proxy [proxyNamespace] => DoctrineORMModule\Proxy [entityNamespaces] => Array ( ) [customStringFunctions] => Array ( [unix_timestamp] => Swing\Utils\UnixTimestamp ) [classMetadataFactoryName] => Doctrine\ORM\Mapping\ClassMetadataFactory [metadataCacheImpl] => Doctrine\Common\Cache\ArrayCache Object ( [data:Doctrine\Common\Cache\ArrayCache:private] => Array ( [DoctrineNamespaceCacheKey[DoctrineModule]] => 1 [DoctrineModule[TDS\Entity\Courses@[Annot]][1]] => Array ( [Doctrine\ORM\Mapping\Table] => Doctrine\ORM\Mapping\Table Object ( [name] => courses [schema] => [indexes] => [uniqueConstraints] => [options] => Array ( ) ) [Doctrine\ORM\Mapping\Entity] => Doctrine\ORM\Mapping\Entity Object ( [repositoryClass] => [readOnly] => ) ) [DoctrineModule[TDS\Entity\Courses$id@[Annot]][1]] => Array ( [Doctrine\ORM\Mapping\Column] => Doctrine\ORM\Mapping\Column Object ( [name] => id [type] => integer [length] => [precision] => 0 [scale] => 0 [unique] => [nullable] => [options] => Array ( ) [columnDefinition] => ) [Doctrine\ORM\Mapping\Id] => Doctrine\ORM\Mapping\Id Object ( ) [Doctrine\ORM\Mapping\GeneratedValue] => Doctrine\ORM\Mapping\GeneratedValue Object ( [strategy] => IDENTITY ) ) [DoctrineModule[TDS\Entity\Courses$name@[Annot]][1]] => Array ( [Doctrine\ORM\Mapping\Column] => Doctrine\ORM\Mapping\Column Object ( [name] => name [type] => string [length] => 64 [precision] => 0 [scale] => 0 [unique] => [nullable] => [options] => Array ( ) [columnDefinition] => ) ) [DoctrineModule[TDS\Entity\Courses$CLASSMETADATA][1]] => Doctrine\ORM\Mapping\ClassMetadata Object ( [name] => TDS\Entity\Courses [namespace] => TDS\Entity [rootEntityName] => TDS\Entity\Courses [customGeneratorDefinition] => [customRepositoryClassName] => [isMappedSuperclass] => [isEmbeddedClass] => [parentClasses] => Array ( ) [subClasses] => Array ( ) [embeddedClasses] => Array ( ) [namedQueries] => Array ( ) [namedNativeQueries] => Array ( ) [sqlResultSetMappings] => Array ( ) [identifier] => Array ( [0] => id ) [inheritanceType] => 1 [generatorType] => 4 [fieldMappings] => Array ( [id] => Array ( [fieldName] => id [type] => integer [scale] => 0 [length] => [unique] => [nullable] => [precision] => 0 [columnName] => id [id] => 1 ) [name] => Array ( [fieldName] => name [type] => string [scale] => 0 [length] => 64 [unique] => [nullable] => [precision] => 0 [columnName] => name ) ) [fieldNames] => Array ( [id] => id [name] => name ) [columnNames] => Array ( [id] => id [name] => name ) [discriminatorValue] => [discriminatorMap] => Array ( ) [discriminatorColumn] => [table] => Array ( [name] => courses ) [lifecycleCallbacks] => Array ( ) [entityListeners] => Array ( ) [associationMappings] => Array ( ) [isIdentifierComposite] => [containsForeignIdentifier] => [idGenerator] => Doctrine\ORM\Id\IdentityGenerator Object ( [sequenceName:Doctrine\ORM\Id\IdentityGenerator:private] => ) [sequenceGeneratorDefinition] => [tableGeneratorDefinition] => [changeTrackingPolicy] => 1 [isVersioned] => [versionField] => [cache] => [reflClass] => ReflectionClass Object ( [name] => TDS\Entity\Courses ) [isReadOnly] => [namingStrategy:protected] => Doctrine\ORM\Mapping\DefaultNamingStrategy Object ( ) [reflFields] => Array ( [id] => ReflectionProperty Object ( [name] => id [class] => TDS\Entity\Courses ) [name] => ReflectionProperty Object ( [name] => name [class] => TDS\Entity\Courses ) ) [instantiator:Doctrine\ORM\Mapping\ClassMetadataInfo:private] => Doctrine\Instantiator\Instantiator Object ( ) ) [DoctrineModule[TDS\Entity\CoursesLevelsPlaces@[Annot]][1]] => Array ( [Doctrine\ORM\Mapping\Table] => Doctrine\ORM\Mapping\Table Object ( [name] => courses_levels_places [schema] => [indexes] => Array ( [0] => Doctrine\ORM\Mapping\Index Object ( [name] => courses [columns] => Array ( [0] => id_course ) [flags] => [options] => ) [1] => Doctrine\ORM\Mapping\Index Object ( [name] => levels [columns] => Array ( [0] => id_level ) [flags] => [options] => ) [2] => Doctrine\ORM\Mapping\Index Object ( [name] => places [columns] => Array ( [0] => id_place ) [flags] => [options] => ) [3] => Doctrine\ORM\Mapping\Index Object ( [name] => time_slot [columns] => Array ( [0] => id_time_slot ) [flags] => [options] => ) ) [uniqueConstraints] => [options] => Array ( ) ) [Doctrine\ORM\Mapping\Entity] => Doctrine\ORM\Mapping\Entity Object ( [repositoryClass] => [readOnly] => ) ) [DoctrineModule[TDS\Entity\CoursesLevelsPlaces$id@[Annot]][1]] => Array ( [Doctrine\ORM\Mapping\Column] => Doctrine\ORM\Mapping\Column Object ( [name] => id [type] => integer [length] => [precision] => 0 [scale] => 0 [unique] => [nullable] => [options] => Array ( ) [columnDefinition] => ) [Doctrine\ORM\Mapping\Id] => Doctrine\ORM\Mapping\Id Object ( ) [Doctrine\ORM\Mapping\GeneratedValue] => Doctrine\ORM\Mapping\GeneratedValue Object ( [strategy] => IDENTITY ) ) [DoctrineModule[TDS\Entity\CoursesLevelsPlaces$idCourse@[Annot]][1]] => Array ( [Doctrine\ORM\Mapping\ManyToOne] => Doctrine\ORM\Mapping\ManyToOne Object ( [targetEntity] => TDS\Entity\Courses [cascade] => [fetch] => LAZY [inversedBy] => ) [Doctrine\ORM\Mapping\JoinColumns] => Doctrine\ORM\Mapping\JoinColumns Object ( [value] => Array ( [0] => Doctrine\ORM\Mapping\JoinColumn Object ( [name] => id_course [referencedColumnName] => id [unique] => [nullable] => 1 [onDelete] => [columnDefinition] => [fieldName] => ) ) ) ) [DoctrineModule[TDS\Entity\CoursesLevelsPlaces$idLevel@[Annot]][1]] => Array ( [Doctrine\ORM\Mapping\ManyToOne] => Doctrine\ORM\Mapping\ManyToOne Object ( [targetEntity] => TDS\Entity\Levels [cascade] => [fetch] => LAZY [inversedBy] => ) [Doctrine\ORM\Mapping\JoinColumns] => Doctrine\ORM\Mapping\JoinColumns Object ( [value] => Array ( [0] => Doctrine\ORM\Mapping\JoinColumn Object ( [name] => id_level [referencedColumnName] => id [unique] => [nullable] => 1 [onDelete] => [columnDefinition] => [fieldName] => ) ) ) ) [DoctrineModule[TDS\Entity\CoursesLevelsPlaces$idPlace@[Annot]][1]] => Array ( [Doctrine\ORM\Mapping\ManyToOne] => Doctrine\ORM\Mapping\ManyToOne Object ( [targetEntity] => TDS\Entity\Places [cascade] => [fetch] => LAZY [inversedBy] => ) [Doctrine\ORM\Mapping\JoinColumns] => Doctrine\ORM\Mapping\JoinColumns Object ( [value] => Array ( [0] => Doctrine\ORM\Mapping\JoinColumn Object ( [name] => id_place [referencedColumnName] => id [unique] => [nullable] => 1 [onDelete] => [columnDefinition] => [fieldName] => ) ) ) ) [DoctrineModule[TDS\Entity\CoursesLevelsPlaces$idTimeSlot@[Annot]][1]] => Array ( [Doctrine\ORM\Mapping\ManyToOne] => Doctrine\ORM\Mapping\ManyToOne Object ( [targetEntity] => TDS\Entity\TimeSlot [cascade] => [fetch] => LAZY [inversedBy] => ) [Doctrine\ORM\Mapping\JoinColumns] => Doctrine\ORM\Mapping\JoinColumns Object ( [value] => Array ( [0] => Doctrine\ORM\Mapping\JoinColumn Object ( [name] => id_time_slot [referencedColumnName] => id [unique] => [nullable] => 1 [onDelete] => [columnDefinition] => [fieldName] => ) ) ) ) [DoctrineModule[TDS\Entity\CoursesLevelsPlaces$CLASSMETADATA][1]] => Doctrine\ORM\Mapping\ClassMetadata Object ( [name] => TDS\Entity\CoursesLevelsPlaces [namespace] => TDS\Entity [rootEntityName] => TDS\Entity\CoursesLevelsPlaces [customGeneratorDefinition] => [customRepositoryClassName] => [isMappedSuperclass] => [isEmbeddedClass] => [parentClasses] => Array ( ) [subClasses] => Array ( ) [embeddedClasses] => Array ( ) [namedQueries] => Array ( ) [namedNativeQueries] => Array ( ) [sqlResultSetMappings] => Array ( ) [identifier] => Array ( [0] => id ) [inheritanceType] => 1 [generatorType] => 4 [fieldMappings] => Array ( [id] => Array ( [fieldName] => id [type] => integer [scale] => 0 [length] => [unique] => [nullable] => [precision] => 0 [columnName] => id [id] => 1 ) ) [fieldNames] => Array ( [id] => id ) [columnNames] => Array ( [id] => id ) [discriminatorValue] => [discriminatorMap] => Array ( ) [discriminatorColumn] => [table] => Array ( [name] => courses_levels_places [indexes] => Array ( [courses] => Array ( [columns] => Array ( [0] => id_course ) ) [levels] => Array ( [columns] => Array ( [0] => id_level ) ) [places] => Array ( [columns] => Array ( [0] => id_place ) ) [time_slot] => Array ( [columns] => Array ( [0] => id_time_slot ) ) ) ) [lifecycleCallbacks] => Array ( ) [entityListeners] => Array ( ) [associationMappings] => Array ( [idCourse] => Array ( [fieldName] => idCourse [joinColumns] => Array ( [0] => Array ( [name] => id_course [unique] => [nullable] => 1 [onDelete] => [columnDefinition] => [referencedColumnName] => id ) ) [cascade] => Array ( ) [inversedBy] => [targetEntity] => TDS\Entity\Courses [fetch] => 2 [type] => 2 [mappedBy] => [isOwningSide] => 1 [sourceEntity] => TDS\Entity\CoursesLevelsPlaces [isCascadeRemove] => [isCascadePersist] => [isCascadeRefresh] => [isCascadeMerge] => [isCascadeDetach] => [sourceToTargetKeyColumns] => Array ( [id_course] => id ) [joinColumnFieldNames] => Array ( [id_course] => id_course ) [targetToSourceKeyColumns] => Array ( [id] => id_course ) [orphanRemoval] => ) [idLevel] => Array ( [fieldName] => idLevel [joinColumns] => Array ( [0] => Array ( [name] => id_level [unique] => [nullable] => 1 [onDelete] => [columnDefinition] => [referencedColumnName] => id ) ) [cascade] => Array ( ) [inversedBy] => [targetEntity] => TDS\Entity\Levels [fetch] => 2 [type] => 2 [mappedBy] => [isOwningSide] => 1 [sourceEntity] => TDS\Entity\CoursesLevelsPlaces [isCascadeRemove] => [isCascadePersist] => [isCascadeRefresh] => [isCascadeMerge] => [isCascadeDetach] => [sourceToTargetKeyColumns] => Array ( [id_level] => id ) [joinColumnFieldNames] => Array ( [id_level] => id_level ) [targetToSourceKeyColumns] => Array ( [id] => id_level ) [orphanRemoval] => ) [idPlace] => Array ( [fieldName] => idPlace [joinColumns] => Array ( [0] => Array ( [name] => id_place [unique] => [nullable] => 1 [onDelete] => [columnDefinition] => [referencedColumnName] => id ) ) [cascade] => Array ( ) [inversedBy] => [targetEntity] => TDS\Entity\Places [fetch] => 2 [type] => 2 [mappedBy] => [isOwningSide] => 1 [sourceEntity] => TDS\Entity\CoursesLevelsPlaces [isCascadeRemove] => [isCascadePersist] => [isCascadeRefresh] => [isCascadeMerge] => [isCascadeDetach] => [sourceToTargetKeyColumns] => Array ( [id_place] => id ) [joinColumnFieldNames] => Array ( [id_place] => id_place ) 
$qb = $this->getEm()->createQueryBuilder();
$qb->select('clp')->from('TDS\Entity\CoursesLevelsPlaces', 'clp');
$list = $qb->getQuery()->getResult();
foreach ($list as $entity) {
    echo $entity->getId() . PHP_EOL;
}
foreach ($list as $entity) {
    Doctrine\Common\Util\Debug::dump($entity);
}