2016-09-09 3 views
0

내 엔터티의 리포지토리를 재정의하려는 데 약간의 좌절감이 생깁니다.Sylius - 사용자 지정 EntityRepository 구현 방법

특별한 방법으로 내 엔티티 목록을 가져 오려면 사용자 지정 리포지토리 메서드를 만들어야합니다. 하나의 queryBuilder는 HavingOrderBy입니다.

Te 질문은 Sylius를 말하도록 내 설정을 어떻게 구성 할 수 있습니까? 기본값이 아니라 내 맞춤 리포지토리를 가져 가세요.

나는이 시도 :

An exception has been thrown during the rendering of a template ("Undefined method 'findCategoriesMenu'. The method name must start with either findBy or findOneBy!")

답변

3

올바른 저장소를 하위 클래스로 분류하지 않습니다. ResourceControllerSylius\Component\Resource\Repository\RepositoryInterface을 기반으로하는 저장소를 필요로합니다. 당신이 Doctrine\ORM\EntityRepository에서 서브 클래 싱을하고 있기 때문에 그렇지 않을 것이다.

리포지토리는 Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository에서 상속 받거나 직접 인터페이스를 구현해야합니다.

+0

당신이 맞습니다. Steffen! 그것은 작동합니다, 대단히 감사합니다. –

0

내가 대답 :

<?php 

namespace App\Bundle\SyliusBlogBundle\Repository; 

use Doctrine\ORM\EntityRepository; 

class PostCategoryRepository extends EntityRepository 
{ 
    public function findCategoriesMenu() 
    { 
     $queryBuilder = $this->createQueryBuilder('c'); 
     return $queryBuilder 
     ->addSelect('COUNT(p.id) as totalPosts') 
     ->leftJoin('c.posts', 'p') 
     ->andWhere('p.published = true') 
     ->having('totalPosts > 0') 
     ->addGroupBy('p.id') 
     ; 
    } 
} 

나는이 방법을 사용하려고, 심포니 나에게이 오류가 발생합니다 : 이것은 내 저장소는

sylius_resource: 
    resources: 
     dinamic.category: 
      classes: 
       model: App\Bundle\SyliusBlogBundle\Entity\PostCategory 
       repository: App\Bundle\SyliusBlogBundle\Repository\PostCategoryRepository 

입니다 게시물에 올바르게 응답을 붙여 넣으려면 app/console debug:container dinamic.repository.category

Information for Service "dinamic.repository.category" 
===================================================== 

------------------ ------------------------------------------------------------------- 
    Option    Value 
------------------ ------------------------------------------------------------------- 
    Service ID   dinamic.repository.category 
    Class    Dinamic\Bundle\SyliusBlogBundle\Repository\PostCategoryRepository 
    Tags    - 
    Scope    container 
    Public    yes 
    Synthetic   no 
    Lazy    no 
    Synchronized  no 
    Abstract   no 
    Autowired   no 
    Autowiring Types - 
------------------ ------------------------------------------------------------------- 

여기 모두 괜찮습니다.

내가 게시물에 액세스하려고

이 오류가 나타납니다 목록 : 저장소 설정이 설정되지 않은 경우 주요 포스트의

An exception has been thrown during the rendering of a template ("Catchable Fatal Error: Argument 4 passed to Sylius\Bundle\ResourceBundle\Controller\ResourceController::__construct() must implement interface Sylius\Component\Resource\Repository\RepositoryInterface, instance of Dinamic\Bundle\SyliusBlogBundle\Repository\PostCategoryRepository given, called in /Applications/XAMPP/xamppfiles/htdocs/rosasinbox-sylius/app/cache/dev/appDevDebugProjectContainer.php on line 2767 and defined")

오류가 나타납니다. 그럼 내 첫 게시물이 잘못되었습니다, config.yml 저장소 값이 설정되지 않았습니다.

이제 다시 설정하고이 오류가 발생합니다.

죄송합니다.