2013-10-14 2 views
0

2.1 또는 2.2 버전의 symfony를 사용하고 있습니다. 오늘 나는 2.3에서 새 프로젝트를 시작했고 사용자 정의 엔티티 리포지토리를 만드는 데 문제가 발생했습니다.Symfony-2.3 엔터티 저장소 오류

내 기업은 다음과 같습니다

<?php 

    namespace Acme\MyBundle\Entity; 

    use Doctrine\ORM\Mapping as ORM; 

    /** 
    * AnnualProduction 
    * 
    * @ORM\Table(name="Annual_Production") 
    * @ORM\Entity(repositoryClass="Acme\MyBundle\Entity\AnnualproductionRepository") 
    */ 
    class AnnualProduction 
    { 
     /** 
     * @var string 
     * 
     * @ORM\Column(name="device_address", type="string", length=45, nullable=true) 
     */ 
     private $deviceAddress; 

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

     /** 
     * @var integer 
     * 
     * @ORM\Column(name="mese_2", type="integer", nullable=true) 
     */ 

SOME MISSING VAR SET AND GET 


     /** 
     * @var string 
     * 
     * @ORM\Column(name="sens_id", type="string", length=45) 
     * @ORM\Id 
     * @ORM\GeneratedValue(strategy="NONE") 
     */ 
     private $sensId; 

     /** 
     * @var \DateTime 
     * 
     * @ORM\Column(name="AAAA", type="date") 
     * @ORM\Id 
     * @ORM\GeneratedValue(strategy="NONE") 
     */ 
     private $aaaa; 

    /** 
     * Set deviceAddress 
     * 
     * @param string $deviceAddress 
     * @return AnnualProduction 
     */ 
     public function setDeviceAddress($deviceAddress) 
     { 
      $this->deviceAddress = $deviceAddress; 

      return $this; 
     } 

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

     /** 
     * Set mese1 
     * 
     * @param integer $mese1 
     * @return AnnualProduction 
     */ 
     public function setMese1($mese1) 
     { 
      $this->mese1 = $mese1; 

      return $this; 
     } 

     /** 
     * Get mese1 
     * 
     * @return integer 
     */ 
     public function getMese1() 
     { 
      return $this->mese1; 
     } 
     /** 
     * Set sensId 
     * 
     * @param string $sensId 
     * @return AnnualProduction 
     */ 
     public function setSensId($sensId) 
     { 
      $this->sensId = $sensId; 

      return $this; 
     } 

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

     /** 
     * Set aaaa 
     * 
     * @param \DateTime $aaaa 
     * @return AnnualProduction 
     */ 
     public function setAaaa($aaaa) 
     { 
      $this->aaaa = $aaaa; 

      return $this; 
     } 

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

내가 모든 변수를 작성 해달라고 얻을과 기능을 설정합니다. 다음 한국 전기 \ MyBundle \ 법인 \ AnnualproductionRepository.php

저장소 파일의 코드입니다 :

<?php 


namespace Acme\MyBundle\Entity; 


use Doctrine\ORM\EntityRepository; 
use Doctrine\ORM\NoResultException; 
use Acme\MyBundle\Entity\AnnualProduction; 

class AnnualproductionRepository extends EntityRepository 
{ 

    public function findByYearMonthDay($anno, $mese, $giorno, $sensId) 
    { 
     $query = $this->getEntityManager() 
     ->createQuery(" SOME QUERY HERE")->setParameters(array(SOME PARAMETERS                 HERE)); 
     return $query->getSingleResult(); 
    } 
} 

내가 내 컨트롤러 중 하나에 저장소를 전화로 나는 저장소 파일을 만들었습니다 다음 코드를

<?php 

namespace Acme\MyBundle\Controller; 


use Acme\MyBundle\Entity\AnnualProduction; 
use Acme\MyBundle\Entity; 

use Symfony\Component\HttpFoundation\RedirectResponse; 
use Symfony\Component\Security\Core\Exception\AccessDeniedException; 
use Symfony\Bundle\FrameworkBundle\Controller\Controller; 
use Symfony\Component\HttpFoundation\Request; 
use Symfony\Component\HttpFoundation\Response; 
use Symfony\Component\Validator\Constraints\Date; 



class DataController extends Controller{ 

    public function indexUserAction(){ 

* 
* 
* 
* 
* 
    $DailyProduction=$DailyProduction+$em->getRepository('AcmeMyBundle:AnnualProduction')->findByYearMonthDay($year, $month, $day, $productionSensor); 
* 
* 
* 
* 
    } 
} 

하지만 난이 존재 나던 저장소와 컨트롤러 등이 오류가 엔터티의 한 속성에 기본 findBy * 같은 함수 이름을 얻을 수.

ERROR : *> 법인 '한국 전기 \ MyBundle \ 엔티티 \의 AnnualProduction가'더 필드

'yearMonthDay'. You can therefore not call 'findByYearMonthDay' on the entities' repository***

이 문제를 해결하기 위해 몇 가지 조언 가지고이 없다? 이 코드는 symfony 2.2에서 커스텀 엔티티 저장소를 포함시키기 위해 보통 추가하는 것과 동일하지만 어떤 이유 때문에 작동을 거부합니다. 시간과 도움을 요청하십시오.

답변

2

문제는/src/acme/myBundle/config/doctrine에 저장된 entity.orm.xml 파일이 엔티티 파일보다 높은 우선 순위를 가졌기 때문에 내가 변경 한 엔티티 wasent를 읽는.

해결 방법 : 터미널 php 명령을 통해 엔티티 생성을 주석 처리 한 후 모든 entity.orm.xml 파일을 삭제하십시오. 답장을 위해

0

저장소의 네임 스페이스가 잘못되었습니다. 네임 스페이스 대신 Acme \ MyBundle \ Entity \ Repository가 있어야합니다. 파일 경로는 Acme/MyBundle/Entity/Repository/AnnualProduction이어야합니다.

당신은 또한 당신의 엔티티 폴더 및 모든 기관이 필요로 그게 전부가 저장 될 당신이 다음 폴더를라는 저장소를 볼 수

php app/console doctrine:generate:entities Acme 

를 통해 교리가 당신을 위해 모든 엔티티를 생성 할 수 있도록해야한다.

+0

tx. @ORM \ Entity (repositoryClass = "Acme \ MyBundle \ Entity \ AnnualConsumptionRepository") TO : @ORM \ Entity (repositoryClass = "Acme \ MyBundle \ Entity \ Repository \ AnnualConsumption") 엔티티 주석 FROM에서 네임 스페이스를 변경했습니다. 그런 다음 명령을 사용합니다. php app/console doctrine : generate : 엔티티 Acme하지만 엔티티 만 생성되고 리포지토리 폴더는 생성되지 않고 리포지토리 파일이 생성되지 않습니다. 내가 뭔가 잘못하고 있는거야? – groot

+0

나는이 게시물에서 entity/repository automaticaly를 생성하지 않는다는 사실에 대한 answare를 발견했다 : http://stackoverflow.com/questions/14115143/symfony2s-doctrinegenerateentities-doesnt-generate-repo-classes 나는 폴더와 파일을 생성하는 사실. 이 경우 제 초기 구성과 제안 사항간에 차이가 없습니다.엔티티/저장소 forlder를 사용하여 네임 스페이스를 시험해 보았고 파일이 수동으로 생성되었지만 문제는 동일하게 유지됩니다. – groot