Accessing “dot” namespaced services in Twig view

被刻印的时光 ゝ 提交于 2019-12-10 22:12:42

问题


I know that I can access registered services by using the dot notation in a Twig template (example app.request.host). However, if I've created my own namespaced service (in this case tagframe.photoservice), when I try to access it, I am given an error that the method "tagframe" doesn't exist on the object "Silex\Application". Is it possible to access services that have been dot namespaced? In other words, a service that I would normally access using $app['tagframe.photoservice'] in the controller?


回答1:


Yes, just like accessing array:

{{ app["tagframe.photoservice"].resizePhoto() }}


来源:https://stackoverflow.com/questions/12538766/accessing-dot-namespaced-services-in-twig-view

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!