我想在我的symfony(2.8)项目中添加Notifications系统,我认为Sonata Notification Bundle可以提供帮助,但事实证明我不知道如何使用它,我安装得很好,但我不知道如何使用它在我的项目中 . 我需要一些关于这个包的帮助,一些教程左右 . 还是有其他方式使用通知系统,请告诉我,提前谢谢 That the controller that i want to use notification bundle
namespace LocationBundle \ Controller;
使用Symfony \ Component \ HttpFoundation \ Request;使用Symfony \ Bundle \ FrameworkBundle \ Controller \ Controller;
使用LocationBundle \ Entity \ Agence;使用Symfony \ Component \ HttpFoundation \ JsonResponse;
/ ** * Agence控制器 . * * /类AgenceController扩展Controller {/ ** *列出所有Agence实体 . * * / public function indexAction(){
$ em = $ this-> getDoctrine() - > getManager();
$agences = $em->getRepository('LocationBundle:Agence')->findAll();
return $this->render('agence/index.html.twig', array(
'agences' => $agences,
));
}
/**
* Creates a new Agence entity.
*
*/
public function newAction(Request $request)
{
$agence = new Agence();
$form = $this->createForm('LocationBundle\Form\AgenceType', $agence);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($agence);
$em->flush();
return $this->redirectToRoute('agence_show', array('id' => $agence->getId()));
}
return $this->render('agence/new.html.twig', array(
'agence' => $agence,
'form' => $form->createView(),
));
}
/**
* Finds and displays a Agence entity.
*
*/
public function showAction(Agence $agence)
{
$deleteForm = $this->createDeleteForm($agence);
return $this->render('agence/show.html.twig', array(
'agence' => $agence,
'delete_form' => $deleteForm->createView(),
));
}
/**
* Displays a form to edit an existing Agence entity.
*
*/
public function editAction(Request $request, Agence $agence)
{
$deleteForm = $this->createDeleteForm($agence);
$editForm = $this->createForm('LocationBundle\Form\AgenceType', $agence);
$editForm->handleRequest($request);
if ($editForm->isSubmitted() && $editForm->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($agence);
$em->flush();
return $this->redirectToRoute('agence_edit', array('id' => $agence->getId()));
}
return $this->render('agence/edit.html.twig', array(
'agence' => $agence,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
));
}
/**
* Deletes a Agence entity.
*
*/
public function deleteAction(Request $request, Agence $agence)
{
$form = $this->createDeleteForm($agence);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->remove($agence);
$em->flush();
}
return $this->redirectToRoute('agence_index');
}
/**
* Creates a form to delete a Agence entity.
*
* @param Agence $agence The Agence entity
*
* @return \Symfony\Component\Form\Form The form
*/
private function createDeleteForm(Agence $agence)
{
return $this->createFormBuilder()
->setAction($this->generateUrl('agence_delete', array('id' => $agence->getId())))
->setMethod('DELETE')
->getForm()
;
}
1 回答
我很确定Sonata Notification Bundle不是您正在搜索的内容 . Headers 中的“通知”一词在您的情况下有点误导 . Bundle用于使用像RabbitMQ这样的队列系统推迟动作/事件 .
对于您正在搜索的内容:看看Symfony自己的"Flash Messages":http://symfony.com/doc/current/book/controller.html#flash-messages
它非常容易实现,您不需要额外的捆绑包 .