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 You must define some services to add custom repositories. The repository class must be obtained from If you are building an organization that should not be linked to any organization Just create a service and inject the necessary dependencies. Since you are not using ORM features of any theory in a custom repository, there is no need to increase $ 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.
& 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;
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
& 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;
EntityManager .
name space Acme \ FQCN; Use \ principle \ DBAL \ connection; Class MiscRepository {protected $ conn; Public function __ composition (connection $ conn) {$ this- & gt; Conn = $ conn; }}
Comments
Post a Comment