Symfony Custom Repository不适用于prod env

时间:2017-08-02 12:29:05

标签: symfony doctrine-orm repository production-environment

我制作了一个自定义存储库" finByCriteria"在客户端实体上,它确实可以在我的本地环境中工作,但它在我的生产环境中工作,我无法理解为什么。

这是日志中的错误:

 Entity 'CER\\PFDBundle\\Entity\\Client' has no field 'criteria'. You can      therefore not call 'findByCriteria' on the entities' repository at /var/www  /html/PROfil_Developpement/vendor/doctrine/orm/lib/Doctrine/ORM/ORMException.php:184)"} [

我的客户实体:

<?php

namespace CER\PFDBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;

/**
 * Client
 *
 * @ORM\Table(name="client", indexes= {@ORM\Index(name="FK_client_id_activite_principale", columns={"id_activite_principale"}), @ORM\Index(name="FK_client_id_domaine_activite", columns={"id_domaine_activite"})})
 * @ORM\Entity(repositoryClass="CER\PFDBundle\Repository\ClientRepository")
 */
 class Client
 {
/**
 * @var integer
 *
 * @ORM\Column(name="id", type="integer")
 * @ORM\Id
 * @ORM\GeneratedValue(strategy="IDENTITY")
 */
private $id;
}

客户端自定义存储库:

<?php

namespace CER\PFDBundle\Repository;

use Doctrine\ORM\EntityRepository;

class ClientRepository extends EntityRepository
{
    public function findByCriteria($raisonSociale, $nom, $prenom, $numAdherent)
    {
        return $this->getEntityManager()
            ->createQuery(
                "SELECT c FROM PFDBundle:Client c "
                . " WHERE c.raisonSociale LIKE :raisonSociale"
                . " OR c.nom LIKE :nom"
                . " OR c.prenom LIKE :prenom"
                . " OR c.numAdherent = :numAdherent"
                . " ORDER BY c.id ASC")
            ->setParameters(array('raisonSociale' => $raisonSociale,
                'nom' => $nom,
                'prenom' => $prenom,
                'numAdherent' => $numAdherent
            ))
            ->setMaxResults(10)
            ->getResult();
    }
}

我调用自定义查询的控制器:

public function searchAction(Request $request)
{
    $client = new Client();

    $form = $this->createForm('CER\PFDBundle\Form\ClientSearchType', $client);
    $form->handleRequest($request);

    if ($form->isSubmitted()) {
        $client = $this->getDoctrine()->getRepository('PFDBundle:Client', 'pfd')->findByCriteria(
            $form->getData()->getRaisonSociale(),
            $form->getData()->getNom(),
            $form->getData()->getPrenom(),
            $form->getData()->getNumAdherent()
        );

        if(!$client || !$form->getData()->getRaisonSociale() && !$form->getData()->getNom() && !$form->getData()->getPrenom() && !$form->getData()->getNumAdherent()) {
            $this->get('session')->getFlashBag()->add('danger', "Aucun client n'a été trouvé");

            return $this->render('client/searchError.html.twig', array(
                'form' => $form->createView(),
                'agent' => $this->get('session')->get('agent')
            ));
        }

        return $this->redirectToRoute('customer_show', array(
            'id' => $client[0]->getId(),
            'agent' => $this->get('session')->get('agent')
        ));
    }

    return $this->render('client/search.html.twig', array(
        'client' => $client,
        'form' => $form->createView(),
        'agent' => $this->get('session')->get('agent')
    ));
}

我按照这些步骤更新prod环境: https://symfony.com/doc/current/deployment.html

谢谢你的帮助!

0 个答案:

没有答案