2016-12-08 1 views
-1

カスタムDoctrineのORMリポジトリを作成し拡張しようとしていますが、動作させる方法が見つかりません。今のところ、これは私が持っているものです。Doctrineのリポジトリを拡張できません

元リポジトリ

//AppBundle\Repository\LocaleRepository.php 

namespace AppBundle\Repository; 

use Doctrine\ORM\EntityRepository; 
use JMS\DiExtraBundle\Annotation as DI; 

class LocaleRepository extends EntityRepository 
{ 

    protected myCustomFunction(){ 
    } 
} 

拡張リポジトリ

//OfficeBundle\Repository\OfficeRepository.php 

namespace OfficeBundle\Repository; 

use AppBundle\Repository\LocaleRepository; 

class OfficeRepository extends LocaleRepository 
{ 
    //Empty class 
} 

マイentiy:

namespace OfficeBundle\Entity; 
// some calls to traits 
use Doctrine\ORM\Mapping as ORM; 

/** 
* Office 
* 
* @ORM\Table(name="office__office") 
* @ORM\Entity(repositoryClass="OfficeBundle\Repository\OfficeRepository") 
*/ 
class Office implements TranslatableInterface{ 
    //... 
} 

そして最後にコール:

$em = $this->getDoctrine()->getManager(); 
$this->getEntityManager(); 
$office=$em->getRepository('OfficeBundle:Office')->myCustomeFunction($slug); 

このtrows例外:

​​

私はOfficeRepository内myCustomeFunctionを配置する場合、それは正常に動作しますが、それはextendindリポジトリの目的をダウンさせます。また、コントローラによって読み込まれたリポジトリは正しいものであり、クラスには「OfficeBundle \ Repository \ OfficeRepository」と表示されます。

最後に私はオフィスエンティティでKNP DoctrineBehaviors(翻訳可能)を使用しています。

答えて

4

リポジトリクラス外で使用する場合は、publicメソッドを作成する必要があります。

class LocaleRepository extends EntityRepository 
{ 

    public function myCustomFunction() 
    { 
     .... 
    } 
} 
+0

ありがとうございました。私はダンプです –

関連する問題