2016-03-02 74 views
2

我有一個類Symfony的自定義庫類工作不

/** 
* @ORM\Table(name="registration_number") 
* @ORM\Entity 
* @ORM\Entity(repositoryClass="PNC\MISDashboardBundle\Repositories\RegistrationNumberRepository") 
* @ORM\HasLifecycleCallbacks 
* @ORM\[email protected]({"RegistrationNumberListener"}) 
*/ 
class RegistrationNumber { 
} 

和回購類

namespace PNC\MISDashboardBundle\Repositories; 
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException; 
use Doctrine\ORM\EntityRepository; 
use Doctrine\ORM\NoResultException; 

/** 
* RegistrationNumberRepository 
* 
* This class was generated by the Doctrine ORM. Add your own custom 
* repository methods below. 
*/ 
class RegistrationNumberRepository extends EntityRepository { 

    public function findByTotalMatches($keyword) 
    { 
     /* your awesome code block */ 
     return 34; 
    } 
} 

和我打電話這樣的方法;

$check = $em->getRepository('PNCMISDashboardBundle:RegistrationNumber') 
              ->findTotalMatches(5); 

但它說,

未定義的方法'findTotalMatches'。方法名稱必須以 開頭,無論是findBy還是findOneBy!

我已經建立了很多其他的自定義回購和作品,我不知道這個錯誤。有沒有人提示這有什麼問題。

+3

也許有'@ORM \ Entity'兩次(實際上是三次)是問題所在。我認爲你應該清理「RegistrationNumber」的註釋並重試。 – Yoshi

回答

2

正如評論所說,

變化:

/** 
* @ORM\Table(name="registration_number") 
* @ORM\Entity 
* @ORM\Entity(repositoryClass="PNC\MISDashboardBundle\Repositories\RegistrationNumberRepository") 
* @ORM\HasLifecycleCallbacks 
* @ORM\[email protected]({"RegistrationNumberListener"}) 
*/ 
class RegistrationNumber { 

要:

/** 
* @ORM\Table(name="registration_number") 
* @ORM\Entity(repositoryClass="PNC\MISDashboardBundle\Repositories\RegistrationNumberRepository") 
* @ORM\HasLifecycleCallbacks 
* @ORM\EntityListeners({"RegistrationNumberListener"}) 
*/ 
class RegistrationNumber { 

,它應該工作。

+0

通過這樣做,事件監聽器不能正常工作。 –

+0

之前是否工作? – chalasr

+0

是的,回購工作正常,但只是檢查了聽者不工作。 –