如何使用 Silex 中的“渲染"在 Twig 中插入控制器 [英] How to insert a Controller in Twig with “render” in Silex

查看:32
本文介绍了如何使用 Silex 中的“渲染"在 Twig 中插入控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

它应该在 Silex 中使用 symfony/twig-bridge 吗?

Should it work in Silex with symfony/twig-bridge ?

{{ render(controller('MyController')) }}

现在我有这样的消息:

Twig_Error_Syntax:..."中不存在控制器"功能

Twig_Error_Syntax: The function "controller" does not exist in "...

推荐答案

我发现这有效:

{{ render(controller('services.controller:action', {[params]}) }}

并且您可以将控制器定义为服务:

And you can define the controller as a service:

$app['services.controller'] = function() use ($dependecy1, .., $dependencyN){
    return new \\PathToYourControllerClass($dependecy1, .., $dependencyN);
} 

这篇关于如何使用 Silex 中的“渲染"在 Twig 中插入控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆