I'm really new in Symfony 2 and Doctrine, and have a simple problem:
There is a pretty simple code in my repository:
<?php namespace BakeryIT\BakeryBundle\Entity; use Doctrine\ORM\EntityRepository; class ProjectRepository extends EntityRepository { public function findHistory(){ return $this->getEntityManager() ->createQueryBuilder() ->select('p') ->from('Project','p') ->getQuery() ->getResult(); } }
And two simple functions in my controller:
<?php namespace BakeryIT\BakeryBundle\Controller; /* ... */ class ProjectController extends Controller { public function indexAction() { return $this->index('Project', 'findHistory'); } }
And Controller looks like this:
public function index($entity, $query = 'findAll') { $repository = $this->getDoctrine() ->getRepository('BakeryBundle:'.$entity); $data = $repository->$query(); return $this->render('BakeryBundle:'.$entity.':index.html.twig', array('data' => $data)); }
This code throw me the Semantical Error [Semantical Error] line 0, col 14 near 'Project p': Error: Class 'Project' is not defined.
On the other hand everything works perfectly if I change this line in my repository:
->from('Project','p')
to
->from('BakeryIT\BakeryBundle\Entity\Project','p')
I don't know why this example doesn't work in the first case. Namespace in my BakeryIT\BakeryBundle\Entity\Project is set in this way:
namespace BakeryIT\BakeryBundle\Entity; use Doctrine\ORM\Mapping as ORM; /** * Project * * @ORM\Table() * @ORM\Entity(repositoryClass="BakeryIT\BakeryBundle\Entity\ProjectRepository") */ class Project { /* .. */ }