The method name must start with either findBy or findOneBy. Undefined method Symfony?

前端 未结 8 1996
梦谈多话
梦谈多话 2020-11-27 05:22

I am working through part4 of Symfony2, and while updating the controller and helper class code i got the following error message

Undefined method \'getLates         


        
相关标签:
8条回答
  • 2020-11-27 05:54

    In case you are using PHP-FPM then this issue might persist even after all the above solutions you have tried then use sudo service php5-fpm restart which did the trick for me.

    0 讨论(0)
  • 2020-11-27 05:58

    In Symfony 3 you are probably missing the repository class in your orm.xml file.

    repository-class="Bundle\Repository\MyRepository"
    

    Example:

    <doctrine-mapping>
        <entity name="Bundle\Entity\MyEntity"
                table="tablename"
                repository-class="Bundle\Repository\MyRepository">
            <id name="id" type="integer" column="id">
                <generator strategy="AUTO"/>
            </id>
        </entity>
    </doctrine-mapping>
    
    0 讨论(0)
  • 2020-11-27 05:59

    If youre using yml as config files for your entities try adding this:

    Blogger\BlogBundle\Entity\Blog:
        type: entity
        table: Blog
        repositoryClass: Blogger\BlogBundle\Repository\BlogRepository
        ...
    

    and then as mentioned above:

    php app/console doctrine:generate:entities Blogger
    
    0 讨论(0)
  • 2020-11-27 06:01

    The other solution is to delete all the orm.xml files added by generated entities. If you move the folder or delete, your mapping with repository will be operationnal.

    0 讨论(0)
  • 2020-11-27 06:05
     * @ORM\Entity(repositoryClass="Blogger\BlogBundle\Repository\BlogRepository")
    

    Try putting the repository class at the same directory next to the Entity class:

         * @ORM\Entity(repositoryClass="Blogger\BlogBundle\BlogRepository")
    
    0 讨论(0)
  • 2020-11-27 06:10

    Make sure that you have modified your entity class:

    // src/Blogger/BlogBundle/Entity/Blog.php
    /**
     * @ORM\Entity(repositoryClass="Blogger\BlogBundle\Repository\BlogRepository")
     * @ORM\Table(name="blog")
     * @ORM\HasLifecycleCallbacks()
     */
    class Blog
    {
        // ..
    }
    

    the annotation @ORM\Entity(repositoryClass="Blogger\BlogBundle\Repository\BlogRepository") is required.

    And don't forget to regenerate entities:

    php app/console doctrine:generate:entities Blogger
    

    UPDATE

    Remove annotation @ORM\Entity. It overrides correct annotation @ORM\Entity(repositoryClass="Blogger\BlogBundle\Repository\BlogRepository")

    0 讨论(0)
提交回复
热议问题