Having a custom repository not associated to an entity in Symfony 2 / Doctrine 2? -


Can not a custom repository be associated with one unit in Symphony 2 and principle 2? I want to put it in some basic SQL which is not well fit in other repositories (this can refer to abstract or entity hierarchy).

How to control code $ this-> getDoctrine () - & gt; GetRepositoty (/ * * * / /) should be replaced? However, only one repository can be connected to the unit manager. However, the number of repositories can be as much as you want.

You must define some services to add custom repositories.

  & lt ;! - My custom repository - & gt; & Lt; Service id = "acme.repository.my_entity" class = "Acme \ FQCN \ MyEntityRepository" & gt; & Lt; Logic type = "service" id = "doctrine.orm.entity_manager" /> & Lt; Logic type = "service" id = "acme.metadata.my_entity" /> & Lt; / Services & gt; & Lt ;! - MyEntity metadata - & gt; & Lt; Service id = "acme.metadata.my_entity" class = "theory / ORM \ mapping \ ClassMetaData" & gt; & Lt; Logic & gt; Acme \ FQCN \ MyEntity & lt; / Logic & gt; & Lt; / Services & gt;   

The repository class must be obtained from EntityRepository .

  Namespace Acme \ FQCN; Use the principle / ORM \ EntityRepository; Square Expands MyEntityRepository EntityRepository {/ ** * If you want to inject a custom dependency, you must either add them to * build or create sets. I suggest using the sets * In this case you There will be no need to use the Constructor in this class. * * Public Function __ Composition ($ em, Principle \ ORM \ mapping \ ClassMetadata $ class, $ custom_dependency) * {* Parent: __ generation ($ em, $ class); Unfortunately, you will not be able to get it through the principle service, instead, get it directly from the container:  
  $ This- & gt; Get ('acme.repository.my_entity');   Edit   

If you are building an organization that should not be linked to any organization Just create a service and inject the necessary dependencies.

  & lt ;! - repository for different queries - & gt; & Lt; Service id = "acme.repository.misc" class = "acme \ faxcen \ marsupacrity" & gt; & Lt; Logic type = "service" id = "database_connection" /> & Lt; / Services & gt;   

Since you are not using ORM features of any theory in a custom repository, there is no need to increase EntityManager .

  name space Acme \ FQCN; Use \ principle \ DBAL \ connection; Class MiscRepository {protected $ conn; Public function __ composition (connection $ conn) {$ this- & gt; Conn = $ conn; }}    

Comments