【发布时间】:2014-12-13 16:50:25
【问题描述】:
我是 symfony 世界的新手。 我想在我的服务中使用渲染,但是我收到了这个错误
调用未定义的方法renderView
我知道renderView是
的快捷方式/**
* Returns a rendered view.
*
* @param string $view The view name
* @param array $parameters An array of parameters to pass to the view
*
* @return string The rendered view
*/
public function renderView($view, array $parameters = array())
{
return $this->container->get('templating')->render($view, $parameters);
}
但我不知道我必须在我的服务中注入什么。我什至知道使用php app/console container:debug 命令我可以看到我所有可用的服务,但我不知道如何选择/选择正确的
更新
我尝试添加
arguments: [@mailer,@templating]
但我得到了ServiceCircularReferenceException
更新
我用
更改了我的 service.yml arguments: [@service_container]
甚至我的服务
$email = $this->service_container->get('mailer');
$twig = $this->service_container->get('templating');
用于服务邮件(swift)和渲染。
我认为这不是最好的解决方案。我只想注入 mailer 和 templating
杰森回答后更新 我正在使用 Symfony 2.3
我的服务.yml
services:
EmailService:
class: %EmailService.class%
arguments: [@mailer,@templating,%EmailService.adminEmail%]
我收到了这个ServiceCircularReferenceException
【问题讨论】: