2

I have this same issue as here The method name must start with either findBy or findOneBy. Undefined method Symfony? but the answers don't help. When I run my code

<?php

namespace Map\ViewBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Map\ViewBundle\Entity\Markers;

class DefaultController extends Controller
{
    public function getMarkersAction()
    {
        $em = $this->getDoctrine()->getManager();
        $em->getRepository('MapViewBundle:Markers')
            ->findAllMarkers();
    }
    //...   
}

I get exception

Undefined method 'findAllMarkers'. The method name must start with either findBy or findOneBy!

this is my MarkersRepository file (located in Entity directory)

<?php

namespace Map\ViewBundle\Entity;
use Doctrine\ORM\EntityRepository;

class MarkersRepository extends EntityRepository
{
    public function  findAllMarkers() {
        //this query will be different
        return $this->getEntityManager()
            ->createQuery(
                'SELECT m FROM MapViewBundle:Markers m'
            )
            ->getResult();
    }
}

and this is Markers entity class (located in Entity directory as well)

<?php

namespace Map\ViewBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Table(name="markers")
 * @ORM\Entity(repositoryClass="Map\ViewBundle\Entity\MarkersRepository")
 */
class Markers
{
    /**
     * @var string
     *
     * @ORM\Column(name="name", type="string", length=100, nullable=false)
     */
    private $name;

    /**
     * @var string
     *
     * @ORM\Column(name="description", type="string", length=500, nullable=false)
     */
    private $description;

    /**
     * @var integer
     *
     * @ORM\Column(name="icon", type="integer", nullable=false)
     */
    private $icon;

    /**
     * @var \DateTime
     *
     * @ORM\Column(name="post_date", type="datetime", nullable=false)
     */
    private $postDate;

    /**
     * @var float
     *
     * @ORM\Column(name="lat", type="float", precision=10, scale=0, nullable=false)
     */
    private $lat;

    /**
     * @var float
     *
     * @ORM\Column(name="lng", type="float", precision=10, scale=0, nullable=false)
     */
    private $lng;

    /**
     * @var integer
     *
     * @ORM\Column(name="relevance_degree", type="integer", nullable=false)
     */
    private $relevanceDegree;

    /**
     * @var string
     *
     * @ORM\Column(name="geohash", type="string", length=12, nullable=false)
     */
    private $geohash;

    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @var \Doctrine\Common\Collections\Collection
     *
     * @ORM\ManyToMany(targetEntity="Map\ViewBundle\Entity\Tags", inversedBy="idMarkers")
     * @ORM\JoinTable(name="markers_tags",
     *   joinColumns={
     *     @ORM\JoinColumn(name="id_markers", referencedColumnName="id")
     *   },
     *   inverseJoinColumns={
     *     @ORM\JoinColumn(name="id_tags", referencedColumnName="id")
     *   }
     * )
     */
    private $idTags;

    /**
     * Constructor
     */
    public function __construct()
    {
        $this->idTags = new \Doctrine\Common\Collections\ArrayCollection();
    }


    /**
     * Set name
     *
     * @param string $name
     * @return Markers
     */
    public function setName($name)
    {
        $this->name = $name;

        return $this;
    }

    /**
     * Get name
     *
     * @return string 
     */
    public function getName()
    {
        return $this->name;
    }

    /**
     * Set description
     *
     * @param string $description
     * @return Markers
     */
    public function setDescription($description)
    {
        $this->description = $description;

        return $this;
    }

    /**
     * Get description
     *
     * @return string 
     */
    public function getDescription()
    {
        return $this->description;
    }

    /**
     * Set icon
     *
     * @param integer $icon
     * @return Markers
     */
    public function setIcon($icon)
    {
        $this->icon = $icon;

        return $this;
    }

    /**
     * Get icon
     *
     * @return integer 
     */
    public function getIcon()
    {
        return $this->icon;
    }

    /**
     * Set postDate
     *
     * @param \DateTime $postDate
     * @return Markers
     */
    public function setPostDate($postDate)
    {
        $this->postDate = $postDate;

        return $this;
    }

    /**
     * Get postDate
     *
     * @return \DateTime 
     */
    public function getPostDate()
    {
        return $this->postDate;
    }

    /**
     * Set lat
     *
     * @param float $lat
     * @return Markers
     */
    public function setLat($lat)
    {
        $this->lat = $lat;

        return $this;
    }

    /**
     * Get lat
     *
     * @return float 
     */
    public function getLat()
    {
        return $this->lat;
    }

    /**
     * Set lng
     *
     * @param float $lng
     * @return Markers
     */
    public function setLng($lng)
    {
        $this->lng = $lng;

        return $this;
    }

    /**
     * Get lng
     *
     * @return float 
     */
    public function getLng()
    {
        return $this->lng;
    }

    /**
     * Set relevanceDegree
     *
     * @param integer $relevanceDegree
     * @return Markers
     */
    public function setRelevanceDegree($relevanceDegree)
    {
        $this->relevanceDegree = $relevanceDegree;

        return $this;
    }

    /**
     * Get relevanceDegree
     *
     * @return integer 
     */
    public function getRelevanceDegree()
    {
        return $this->relevanceDegree;
    }

    /**
     * Set geohash
     *
     * @param string $geohash
     * @return Markers
     */
    public function setGeohash($geohash)
    {
        $this->geohash = $geohash;

        return $this;
    }

    /**
     * Get geohash
     *
     * @return string 
     */
    public function getGeohash()
    {
        return $this->geohash;
    }

    /**
     * Get id
     *
     * @return integer 
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Add idTags
     *
     * @param \Map\ViewBundle\Entity\Tags $idTags
     * @return Markers
     */
    public function addIdTag(\Map\ViewBundle\Entity\Tags $idTags)
    {
        $this->idTags[] = $idTags;

        return $this;
    }

    /**
     * Remove idTags
     *
     * @param \Map\ViewBundle\Entity\Tags $idTags
     */
    public function removeIdTag(\Map\ViewBundle\Entity\Tags $idTags)
    {
        $this->idTags->removeElement($idTags);
    }

    /**
     * Get idTags
     *
     * @return \Doctrine\Common\Collections\Collection 
     */
    public function getIdTags()
    {
        return $this->idTags;
    }
}

I tried clear cache and use command

php app/console doctrine:generate:entities Map

but still exception is throw. Anybody see whats wrong with my code?

Solution Removing files: Markers.orm.yml and Tags.orm.yml from Map\ViewBundle\Resources\config\doctrine directory is the solution.

Community
  • 1
  • 1
user3452568
  • 283
  • 3
  • 14
  • Have you tried to delete cache manually from app/cache directory? –  Apr 30 '14 at 20:50
  • Yes, I get still that error – user3452568 Apr 30 '14 at 21:07
  • Your code seems to be completely correct. If you manage to solve the issue, please add your answer here. –  Apr 30 '14 at 21:11
  • Are you sure when you created your bundle you set the alias name as `MapViewBundle` or it might be `ViewBundle` – Javad Apr 30 '14 at 21:15
  • I used `$ php app/console generate:bundle --namespace=Map/ViewBundle` command. Maybe the reason is created Markers Entity from exsiting database table follwing this tutorial [link](http://symfony.com/doc/current/cookbook/doctrine/reverse_engineering.html) – user3452568 Apr 30 '14 at 21:24
  • @JakubPolák Removing files: Markers.orm.yml and Tags.orm.yml from Map\ViewBundle\Resources\config\doctrine directory is the solution. – user3452568 May 01 '14 at 08:55

2 Answers2

3

Start by verifying that you are not getting the correct repository.

$repo = $em->getRepository('MapViewBundle:Markers')
die('Repo Class ' . get_class($repo));

If you do happen to get the correct class then you have a typo.

And make sure you don't have any doctrine/markers.orm.yml or xml files hanging around.

Finally, update your question with the doctrine section in app/config/config.yml

Cerad
  • 48,157
  • 8
  • 90
  • 92
  • 1
    `Doctrine/markers.orm.yml` files are the problem. I removed them and everything is going fine. Arghhh!! Thanks @Cerad, you saved my day – user3452568 May 01 '14 at 08:47
0

This may sound weird but I encountered a similar issue with a custom repository function. Try renaming your Repository function to getAllMarkers() and update the call in the controller and try again. This solved the issue for me on that occasion.

Simon
  • 1,643
  • 7
  • 30
  • 61