Nette 框架 - 从演示者或拿铁模板内部访问、获取服务、服务类模型、组件、助手

问题描述 投票:0回答:1

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

php dependency-injection inversion-of-control ioc-container nette
1个回答
0
投票
  • 自动装配(依赖注入)- 如何从 di 依赖注入容器上下文中自动装配( autowiring )/获取 Nette 中的服务

  • 演示者内部通过 $this->getRouter()、$this->getAction() 等通过此类传递关系访问它

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

    • 演示者内部通过 $this->context-> ($this->context->getByName(), $this->context->getByType()) 访问它,已弃用的过时方式
© www.soinside.com 2019 - 2023. All rights reserved.