简体   繁体   English

zend framework 2-使用全局方法

[英]zend framework 2 - use global method

i need one function which i use in views, hydrator, some controllers and so on... Where i can put it? 我需要一个在视图,水化器,某些控制器等中使用的功能...我可以放在哪里?

Where it would be the best add that can be maintained PHP OOP and zend 2 architecture? 在哪里可以保持PHP OOP和zend 2体系结构的最佳添加?

Thanks 谢谢

It sounds like you should be looking at the Zend\\ServiceManager . 听起来您应该在看Zend \\ ServiceManager You can register factories (functions) and services in the service manager, and technically access them from anywhere in your application. 您可以在服务管理器中注册工厂(功能)和服务,并从技术上从应用程序中的任何位置访问它们。 Your class would need to implement the ServiceLocatorAwareInterface in order to access the service manager, OR you would pass/inject the service into your class/model/hydrator/etc. 您的类将需要实现ServiceLocatorAwareInterface才能访问服务管理器,或者您将服务传递/注入到类/模型/ hydrator / etc中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM