Tôi nhận được dưới đây lỗi,Lỗi: Bạn không thể tạo một dịch vụ ("templating.helper.assets") của một phạm vi hoạt động ("yêu cầu")
[Twig_Error_Runtime]
An exception has been thrown during the rendering of a template ("You cannot create a service ("templating.helper.assets") of an inactive scope ("request").") in "AcmeMessagingBundle:Comment:email.html.twig".
Tôi render mẫu cành lá từ symfony 2 tùy chỉnh console lệnh
Dưới đây là lớp dịch vụ của tôi là thuê bao sự kiện, tôi kích hoạt sự kiện onCommentAddEmail bởi giao diện điều khiển lệnh symfony để gửi email,
class NotificationSubscriber implements EventSubscriberInterface
{
private $container;
public function __construct(ContainerInterface $container)
{
$this->container = $container;
}
public static function getSubscribedEvents()
{
return array(
'comment.add' => array('onCommentAddEmail', 0),
);
}
public function onCommentAddEmail(CommentAddEvent $event)
{
...................
$body = $this->container->get('templating')->render(
'AcmeMessagingBundle:Comment:email.html.twig',
array('template' => $template)
);
.......
}
}
$ cơ thể được truyền cho swiftmailer gửi Một email.
Đây là, định nghĩa dịch vụ của tôi,
Acme \ MessagingBundle \ Subscriber \ NotificationSubscriber
<services>
<service id="notification_subscriber" class="%notification_subscriber.class%">
<argument type="service" id="service_container" />
<tag name="kernel.event_subscriber" />
</service>
</services>
Dưới đây bài nói vấn đề được cố định trong symfony 2.1, nhưng tôi vẫn nhận được lỗi,
https://github.com/symfony/symfony/issues/4514
Tôi đã được xác nhận là http://symfony.com/doc/current/cookbook/service_container/scopes.html, tôi đã chuyển toàn bộ vùng chứa với dịch vụ của tôi.
Hãy nhìn vào phản ứng đối với một vấn đề tương tự (http://stackoverflow.com/a/24409012/1263890) –