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:
use Entity folder: (entity and entityRepository in the same folder)
/project/bundle/entity;
use Repository folder: (entity in entity folder and repository in Repository one)
/project/bundle/entity; /project/entity/repository;
There are any standard about that?
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With