I have already read the existing pages here regarding the same error message declared in the title. Like for example this here:
The method name must start with either findBy or findOneBy. Undefined method Symfony?
However, i did not find working solution. I have done everything according to the manual:
http://symfony.com/doc/3.0/book/doctrine.html#custom-repository-classes
I'm using annotation based configuration and here is the start of the food class:
namespace AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Food
*
* @ORM\Table(name="food")
* @ORM\Entity(repositoryClass="AppBundle\Entity\FoodRepository")
*/
However, the command:
php bin/console doctrine:generate:entities AppBundle
does not generate the FoodRepository repo, so i had to do it manually. Here is the code of the FoodRepository:
<?php
namespace AppBundle\Entity;
use Doctrine\ORM\EntityRepository;
class FoodRepository extends EntityRepository
{
public function findFoodsByName()
{
return $this->getEntityManager()
->createQuery(
'SELECT f FROM AppBundle:Food f WHERE f.foodname LIKE :food'
)
->getResult();
}
}
and here is the slice from the controller:
$em = $this->getDoctrine()->getManager();
$foods = $em->getRepository('AppBundle:Food')
->findFoodsByName();
I have also tried to empty the Doctrine cache with command:
php app/console doctrine:cache:clear-metadata
without results. The problem persists.
Has anyone had the same problem with Symfony and what did you do to solve the problem?