我很难在symfony中添加通知
我使用此捆绑包https://github.com/maximilienGilet/notification-bundle
我已经关注了文档, 但是我遇到了困难
这就是我在控制器中添加的内容(添加名词)
$manager = $this->get('mgilet.notification');
$notif = $manager->createNotification('Nouveau candidat !');
$notif->setMessage('X a entré un candidat');
$notif->setLink('http://symfony.com/');
$manager->addNotification(array($this->getUser()), $notif, true);
return $this->redirectToRoute('index');
这是我在树枝中添加的内容 {{mgilet_notification_render(app.user)}}
但是添加名词之后,我会看到此错误
找不到服务“ mgilet.notification”:即使该服务存在于 应用程序的容器,“ App \ Controller \ TestController”内的容器 是一个较小的服务定位器,仅了解“学说”, “ form.factory”,“ http_kernel”,“ parameter_bag”,“ request_stack”, “路由器”,“ security.authorization_checker”, “ security.csrf.token_manager”,“ security.token_storage”,“序列化器”, “会话”,“模板”和“树枝”服务。尝试使用依赖 而是注射。
答案 0 :(得分:0)
在控制器函数中,尝试使用依赖项注入,如下所示:
public function controllerFunction(Mgilet\NotificationBundle\Manager\NotificationManager $manager)
{
$notif = $manager->createNotification('Nouveau candidat !');
$notif->setMessage('X a entré un candidat');
$notif->setLink('http://symfony.com/');
$manager->addNotification(array($this->getUser()), $notif, true);
return $this->redirectToRoute('index');
}