我使用Zend\Authentication\AuthenticationService
來管理當前登錄的用戶。現在,我希望默認情況下,實體對象在所有ViewModel中都可用,而無需在每個控制器操作中分配用戶對象。所有ViewModels中的用戶標識
有沒有一種很好的方法來做到這一點?或者我是否需要爲ViewModel創建一個工廠並從中注入用戶的身份?在這種情況下,每次我想創建一個不太性感的ViewModel時,我都必須使用ServiceManager。
有沒有更優雅的方式?我可以以某種方式直接從ViewModel(即模板)中訪問AuthenticationService嗎?
'ZfcUser'的auth服務仍然是一個'Zend \ Authentication \ AuthenticationService' btw;) – Ocramius 2013-02-16 02:39:54