custom repository class in symfony2

后端 未结 6 2007
刺人心
刺人心 2020-12-05 17:40

I\'m new in symfony2.I created a repository class when I created an entity class through command line.But I couldn\'t access my custom functions in that repository class. ho

6条回答
  •  自闭症患者
    2020-12-05 18:03

    I think you just forgot to register this repository in your entity. You just have to add in your entity configuration file the repository class.

    In src/Mypro/symBundle/Resources/config/doctrine/Register.orm.yml:

    Mypro\symBundle\Entity\Register:
        type: entity
        repositoryClass: Mypro\symBundle\Entity\RegisterRepository
    

    Don't forget to clear your cache after this change, just in case.

    And if you're using Annotations (instead of yml config) then instead of the above, add something like:

    /**
     * @ORM\Entity(repositoryClass="Mypro\symBundle\Entity\RegisterRepository")
    */
    

    to your Entity class to register the repository

提交回复
热议问题