我是symfony世界的新手。
我想在我的服务中使用render,但是我收到了这个错误
Call to undefined method 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
UPDATE
我改变了我的service.yml
arguments: [@service_container]
甚至我的服务
$email = $this->service_container->get('mailer');
$twig = $this->service_container->get('templating');
使用服务邮件(swift)和渲染。
我不认为这是最好的解决方案。我想注射只邮寄和模板
更新杰森的回答之后
我正在使用Symfony 2.3
我的services.yml
services:
EmailService:
class: %EmailService.class%
arguments: [@mailer,@templating,%EmailService.adminEmail%]
我得到了这个ServiceCircularReferenceException