【问题标题】:Nette framework - accessing , getting services , service classes models, components, helpers from inside presenters or latte templatesNette 框架 - 从演示者或拿铁模板中访问、获取服务、服务类模型、组件、助手
【发布时间】:2022-01-27 13:02:05
【问题描述】:

如何在 Nette 中从演示者(控制器)/内部检索模型、模板的服务?

【问题讨论】:

    标签: php dependency-injection inversion-of-control ioc-container nette


    【解决方案1】:
    • 自动装配(依赖注入)- How to autowire ( autowiring ) / get services in Nette from the di dependency injection container context

    • 在 Presenter 内部通过 $this->getRouter()、$this->getAction() 等通过这种传递关系访问它

    • 在 Latte 模板中作为 $presenter 变量、$presenter->getRouter() 等方法链接,分别为 $presenter->getContext(),它已被弃用,因此如果必须通过模板分配这样的方法链接不可传递访问变量

      • 在演示者内部通过 $this->context-> ($this->context->getByName(), $this->context->getByType()) 访问它,已弃用的过时方式

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-04-23
      • 1970-01-01
      • 1970-01-01
      • 2021-04-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-28
      相关资源
      最近更新 更多