Я пытаюсь создать собственный репозиторий ORM Doctrine и расширить его, но я не могу найти способ заставить его работать. До сих пор это то, что у меня есть:Не удается расширить репозиторий Doctrine
Оригинальный Repository
//AppBundle\Repository\LocaleRepository.php
namespace AppBundle\Repository;
use Doctrine\ORM\EntityRepository;
use JMS\DiExtraBundle\Annotation as DI;
class LocaleRepository extends EntityRepository
{
protected myCustomFunction(){
}
}
Расширенный Repository
//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 за исключением:
Undefined method 'myCustomFunction'. The method name must start with either findBy or findOneBy!
Если я помещаю myCustomeFunction внутри OfficeRepository он работает нормально, но это приносит вниз цель extendind хранилища. Кроме того, репозиторий, загруженный контроллером, является правильным, vardumping класс показывает: «OfficeBundle \ Repository \ OfficeRepository».
Наконец-то я использую KNP DoctrineBehaviors (переводимый) на офисном объекте.
Спасибо, это было так obvius ... Я дамп –