English 中文(简体)
利用杜思纳存放处的服务
原标题:Using services in Doctrine repositories

How would I inject services in Doctrine repositories? Is it a good idea to do so? Should I make a doctrine repository container aware or should I pass services in the function arguments?

For example: I want to use a service called "knp_pager" that paginates queries. I want to have it available in the getArticleList() function of my Article repository so that I can return a paged result.

问题回答

IMHO将knp_pager服务注入贵处,这不是一个好的想法。 存放处不负责放弃你的询问。

为了限制你的询问,我将通过一个任择的<代码>offset。 & an optional length to the Deposit methods which can be produced by the knp_pager. 同样,存放处的责任也得到尊重,你能够轻松地限制你的询问。

您可以确定贵处的服务,在地名2网站上有一本关于此事项的书状。 然后,你可以在集装箱组合中使用固定装置并连接其他服务。

Anyway I would try to keep repository classes as simple as possible (let s say that they should only provide generic data access) and inject them in other services if I need more abstraction on complex operations.





相关问题
Zend and static class properties

I m trying to assign a value to a static class property when defining it: namespace Base; abstract class Skeleton { protected static $entityManager = end_Registry::get("EntityManager"); ......

require_once missing doctrine zend framework

I m integrating doctrine with Zend Framework. I ve hit an error thrown from cli. It seems Zend_Application_Bootstrap_Bootstrap does not have a require_once for ...

doctrine: QueryBuilder vs createQuery?

In Doctrine you can create DQL in 2 ways: EntityManager::createQuery: $query = $em->createQuery( SELECT u FROM MyProjectModelUser u WHERE u.id = ?1 ); QueryBuilder: $qb->add( select , u ) ...

热门标签