Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony2 repository standard folder or namespace

I am creating a Repository to use it with an Entity in a Symfony2 project, but I do not know where to store the class. I have been researching in Internet but I do not have any info about the default namespace o default folder to store the Repositories.

I could "think" in two approaches:

  1. use Entity folder: (entity and entityRepository in the same folder)

    /project/bundle/entity;

  2. use Repository folder: (entity in entity folder and repository in Repository one)

    /project/bundle/entity; /project/entity/repository;

There are any standard about that?

like image 708
unairoldan Avatar asked Aug 13 '12 09:08

unairoldan


2 Answers

You can store them anywhere you want, but the official Symfony book uses

Acme/DemoBundle/Repository/

So I think that would be the more standard way

like image 165
Carlos Granados Avatar answered Oct 18 '22 10:10

Carlos Granados


If somehow Symfony won't find your repository, you can use annotation at entity class to define specific repository namespace\class (in example: "Acme\DemoBundle\Entity\Repository\MyEntityRepository") like this:

use Doctrine\ORM\Mapping as ORM;

/**
*@ORM\Entity(repositoryClass="Acme\DemoBundle\Entity\Repository\MyEntityRepository")
*/
class MyEntity { ... }

Maybe it can be defined through YML, XML or PHP but I use annotations at entities.

like image 21
Peter Laboš Avatar answered Oct 18 '22 11:10

Peter Laboš