Symfony 命令中的 RenderView 使用 [英] RenderView in Symfony Command usage

查看:31
本文介绍了Symfony 命令中的 RenderView 使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 symfony 命令中使用 $this->renderView(不在控制器中)?我对函数renderView"不熟悉,但我必须设置什么才能在命令中使用它?

How can I use $this->renderView inside a symfony Command (not inside a controller)? I new about the function "renderView" but what do I have to setup to use it wihtin a command?

预先感谢您的问候

推荐答案

你的命令类必须扩展 ContainerAwareCommand 抽象类 然后你可以这样做:

Your command class must extends the ContainerAwareCommand abstract class and then you can do:

$this->getContainer()->get('templating')->render($view, $parameters);

当涉及到扩展 ContainerAwareCommand 的命令时,获取容器的正确方法是通过 getContainer() 与控制器快捷方式不同.

When it comes to commands that extend ContainerAwareCommand the proper way to obtain the container is by getContainer() unlike in controller shortcut.

这篇关于Symfony 命令中的 RenderView 使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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