(ZF2 + Doctrine2)查找,FindBy不返回任何结果或错误消息

时间:2014-04-11 09:27:05

标签: doctrine-orm zend-framework2

我正在使用ZF2 + Doctrine2从事一个小型项目。 我有一个学说实体,其描述如下:

<?php

namespace Akplanu\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * Exemplaire
 *
 * @ORM\Table(name="exemplaire", indexes={@ORM\Index(name="fk_Exemplaire_Livre1_idx", columns={"Liv_id"}), @ORM\Index(name="fk_Exemplaire_Donateur1_idx", columns={"Don_id"}), @ORM\Index(name="fk_Exemplaire_Origin_1_idx", columns={"Origin_id"}), @ORM\Index(name="fk_Exemplaire_Etat_Livre1_idx", columns={"Etlv_id"})})
 * @ORM\Entity(repositoryClass="Akplanu\Repository\ExemplaireRepository")
 */
class Exemplaire
{
    /**
     * @var integer
     *
     * @ORM\Column(name="Expl_id", type="integer", nullable=false)
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="IDENTITY")
     */
    private $id;

    /**
     * @var integer
     *
     * @ORM\Column(name="Expl_numEntr", type="integer", nullable=false)
     */
    private $numEntre;

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

    /**
     * @var \DateTime
     *
     * @ORM\Column(name="Expl_datEdit", type="date", nullable=false)
     */
    private $datEdit;

    /**
     * @var boolean
     *
     * @ORM\Column(name="Expl_tome", type="integer", nullable=true)
     */
    private $tome;

    /**
     * @var \DateTime
     *
     * @ORM\Column(name="Expl_datDon", type="date", nullable=true)
     */
    private $dateDon;

    /**
     * @var float
     *
     * @ORM\Column(name="Expl_prix", type="float", precision=10, scale=0, nullable=true)
     */
    private $prix;

    /**
     * @var string
     *
     * @ORM\Column(name="Expl_comment", type="text", nullable=true)
     */
    private $comment;

    /**
     * @var \Akplanu\Entity\Livre
     *
     * @ORM\ManyToOne(targetEntity="Akplanu\Entity\Livre")
     * @ORM\JoinColumns({
     *   @ORM\JoinColumn(name="Liv_id", referencedColumnName="Liv_id")
     * })
     */
    private $livre;

    /**
     * @var \Akplanu\Entity\Donateur
     *
     * @ORM\ManyToOne(targetEntity="Akplanu\Entity\Donateur")
     * @ORM\JoinColumns({
     *   @ORM\JoinColumn(name="Don_id", referencedColumnName="Don_id", nullable=true)
     * })
     */
    private $donateur;


    /**
     * @var \Akplanu\Entity\OrigineExemplaire
     *
     * @ORM\ManyToOne(targetEntity="Akplanu\Entity\OrigineExemplaire")
     * @ORM\JoinColumns({
     *   @ORM\JoinColumn(name="Origin_id", referencedColumnName="Origin_id", nullable=false)
     * })
     */
    private $origine;

    /**
     * @var \Akplanu\Entity\EtatLivre
     *
     * @ORM\ManyToOne(targetEntity="Akplanu\Entity\EtatLivre")
     * @ORM\JoinColumns({
     *   @ORM\JoinColumn(name="Etlv_id", referencedColumnName="Etlv_id", nullable=false)
     * })
     */
    private $etat;

    /**
     * @ORM\Column(name="Expl_datEntree" ,type="date" , nullable=false)
     */
    private $dateEntree;

    /**
     * @ORM\Column(name="Expl_estEmprunter" ,type="boolean" , nullable=false)
     */
    private $estEmprunter;


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

    /**
     * Set numEntre
     *
     * @param integer $numEntre
     * @return Exemplaire
     */
    public function setNumEntre($numEntre)
    {
        $this->numEntre = $numEntre;

        return $this;
    }

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

    /**
     * Set lieuEdit
     *
     * @param string $lieuEdit
     * @return Exemplaire
     */
    public function setLieuEdit($lieuEdit)
    {
        $this->lieuEdit = $lieuEdit;

        return $this;
    }

    /**
     * Get lieuEdit
     *
     * @return string 
     */
    public function getLieuEdit()
    {
        return $this->lieuEdit;
    }

    /**
     * Set datEdit
     *
     * @param \DateTime $datEdit
     * @return Exemplaire
     */
    public function setDatEdit($datEdit)
    {
        $this->datEdit = $datEdit;

        return $this;
    }

    /**
     * Get datEdit
     *
     * @return \DateTime 
     */
    public function getDatEdit()
    {
        return $this->datEdit;
    }

    /**
     * Set tome
     *
     * @param boolean $tome
     * @return Exemplaire
     */
    public function setTome($tome)
    {
        $this->tome = $tome;

        return $this;
    }

    /**
     * Get tome
     *
     * @return boolean 
     */
    public function getTome()
    {
        return $this->tome;
    }

    /**
     * Set dateDon
     *
     * @param \DateTime $dateDon
     * @return Exemplaire
     */
    public function setDateDon($dateDon)
    {
        $this->dateDon = $dateDon;

        return $this;
    }

    /**
     * Get dateDon
     *
     * @return \DateTime 
     */
    public function getDateDon()
    {
        return $this->dateDon;
    }

    /**
     * Set prix
     *
     * @param float $prix
     * @return Exemplaire
     */
    public function setPrix($prix)
    {
        $this->prix = $prix;

        return $this;
    }

    /**
     * Get prix
     *
     * @return float 
     */
    public function getPrix()
    {
        return $this->prix;
    }

    /**
     * Set comment
     *
     * @param string $comment
     * @return Exemplaire
     */
    public function setComment($comment)
    {
        $this->comment = $comment;

        return $this;
    }

    /**
     * Get comment
     *
     * @return string 
     */
    public function getComment()
    {
        return $this->comment;
    }

    /**
     * Set livre
     *
     * @param \Akplanu\Entity\Livre $livre
     * @return Exemplaire
     */
    public function setLivre(\Akplanu\Entity\Livre $livre )
    {
        $this->livre = $livre;

        return $this;
    }

    /**
     * Get livre
     *
     * @return \Akplanu\Entity\Livre 
     */
    public function getLivre()
    {
        return $this->livre;
    }

    /**
     * Set donateur
     *
     * @param \Akplanu\Entity\Donateur $donateur
     * @return Exemplaire
     */
    public function setDonateur(\Akplanu\Entity\Donateur $donateur )
    {
        $this->donateur = $donateur;

        return $this;
    }

    /**
     * Get donateur
     *
     * @return \Akplanu\Entity\Donateur 
     */
    public function getDonateur()
    {
        return $this->donateur;
    }



    /**
     * Set origine
     *
     * @param \Akplanu\Entity\OrigineExemplaire $origine
     * @return Exemplaire
     */
    public function setOrigine(\Akplanu\Entity\OrigineExemplaire $origine )
    {
        $this->origine = $origine;

        return $this;
    }

    /**
     * Get origine
     *
     * @return \Akplanu\Entity\OrigineExemplaire 
     */
    public function getOrigine()
    {
        return $this->origine;
    }

    /**
     * Set etat
     *
     * @param \Akplanu\Entity\EtatLivre $etat
     * @return Exemplaire
     */
    public function setEtat(\Akplanu\Entity\EtatLivre $etat )
    {
        $this->etat = $etat;

        return $this;
    }

    /**
     * Get etat
     *
     * @return \Akplanu\Entity\EtatLivre 
     */
    public function getEtat()
    {
        return $this->etat;
    }


    public function getDateEntree()
    {
        return $this->dateEntree;
    }

    public function setDateEntree($dateEntree)
    {
         $this->dateEntree = $dateEntree;
    }
    public function getEstEmprunter()
    {
        return $this->estEmprunter;
    }

    public function setEstEmprunter($estEmprunter)
    {
        $this->estEmprunter = $estEmprunter;
    }




}

包含以下代码的存储库:

<?php 
namespace Akplanu\Repository;

use Akplanu\Entity\Exemplaire;

use Doctrine\ORM\EntityRepository;

class ExemplaireRepository extends EntityRepository
{

    /**
     * add or update an exemplaire
     */
    public function save(Exemplaire $exemplaire)
    {
        $this->getEntityManager()->persist($exemplaire);
        $this->getEntityManager()->flush();
    }

    /**
     * delete a list exemplaire base on ids array
     */
    public function delete($idsExemplaire)
    {
        $dql = "DELETE FROM Akplanu\Entity\Exemplaire d WHERE d.id IN (:idsExemplaire)";
        $query = $this->getEntityManager()->createQuery($dql);
        $query->setParameter('idsExemplaire',$idsExemplaire);
        $query->execute();
    }

    /**
     * find Exemplaire by id
     */
    public function findById($id)
    {
        return $this->find((int)$id);                   
    }

    /**
     * find exemplaire by name
     */
    public function findByNumeroEntree($numeroEntree)
    {
        return $this->findBy(array('numeroEntree'=>$numeroEntree),array('numeroEntree'=>'asc'));
    }

    /**
     * retrieve list of all exemplaire
     */
    public function getAll()
    {
        return $this->findAll();
    }

    public function getListExemplairesPouvantEtreEmprunter()
    {
        $dql = "SELECT e,l FROM Akplanu\Entity\Exemplaire e
                JOIN e.livre l
                WITH e.estEmprunter = false";
        $query = $this->getEntityManager()->createQuery($dql);
        return $query->getResult();
    }
}

?>

当我通过控制器中的服务调用ExemplaireRepository :: findById()方法时(通过使用ajax请求),即使我按如下方式编辑方法,请求也不会返回任何结果:

/**
 * find Exemplaire by id
 */
public function findById($id)
{

    $dql = "SELECT e,l,d,o,t FROM Akplanu\Entity\Exemplaire e 
            JOIN e.livre l
            JOIN e.donateur d
            JOIN e.origine o
            JOIN e.etat t
            WHERE e.id=:id";
    $query = $this->getEntityManager()->createQuery($dql);
    $query->setParameter('id', $id);
    return $query->getResult();

}

在FireBug控制台中,我有一个比没有任何错误消息的无限显示的wainting图标,但是ExemplaireRepository :: getListExemplairesPouvantEtreEmprunter()运行良好!

有人已经面临这样的问题吗?它可能在哪里?我怎样才能解决它。 提前谢谢。

1 个答案:

答案 0 :(得分:0)

这很可能是代码中的设置错误。我建议使用Zend Framework 2的学说模块。

https://github.com/doctrine/DoctrineORMModule

https://github.com/doctrine/DoctrineModule

自述文件解释了如何使用composer安装模块。