如何使用 Sonata Notification Bundle?
How to use Sonata Notification Bundle?
我想在我的 symfony (2.8) 项目中添加通知系统,我认为 Sonata Notification Bundle 可以提供帮助,但结果我不知道如何使用它,我安装它很好,但我做了不知道如何在我的项目中使用它。
我需要一些关于这个包的帮助,一些教程之类的。
要么
还有另一种使用通知系统的方法吗,请告诉我,
先感谢您
我想使用通知包的控制器
命名空间LocationBundle\Controller;
使用Symfony\Component\HttpFoundation\Request;
使用 Symfony\Bundle\FrameworkBundle\Controller\Controller;
使用LocationBundle\Entity\Agence;
使用 Symfony\Component\HttpFoundation\JsonResponse;
/**
* 代理控制器。
*
*/
class AgenceController 扩展控制器
{
/**
* 列出所有代理实体。
*
*/
public 函数 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()
;
}
我很确定 Sonata Notification Bundle 不是您要搜索的内容。标题中的单词 "Notification" 在您的案例中有点误导。 Bundle 用于使用像 RabbitMQ 这样的 queue 系统来推迟 actions/events。
对于你正在搜索的内容:看看 Symfony 自己的"Flash Messages":http://symfony.com/doc/current/book/controller.html#flash-messages
实施起来非常容易,您不需要额外的捆绑包。
我想在我的 symfony (2.8) 项目中添加通知系统,我认为 Sonata Notification Bundle 可以提供帮助,但结果我不知道如何使用它,我安装它很好,但我做了不知道如何在我的项目中使用它。 我需要一些关于这个包的帮助,一些教程之类的。 要么 还有另一种使用通知系统的方法吗,请告诉我, 先感谢您 我想使用通知包的控制器
命名空间LocationBundle\Controller;
使用Symfony\Component\HttpFoundation\Request; 使用 Symfony\Bundle\FrameworkBundle\Controller\Controller;
使用LocationBundle\Entity\Agence; 使用 Symfony\Component\HttpFoundation\JsonResponse;
/**
* 代理控制器。
*
*/
class AgenceController 扩展控制器
{
/**
* 列出所有代理实体。
*
*/
public 函数 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()
;
}
我很确定 Sonata Notification Bundle 不是您要搜索的内容。标题中的单词 "Notification" 在您的案例中有点误导。 Bundle 用于使用像 RabbitMQ 这样的 queue 系统来推迟 actions/events。
对于你正在搜索的内容:看看 Symfony 自己的"Flash Messages":http://symfony.com/doc/current/book/controller.html#flash-messages
实施起来非常容易,您不需要额外的捆绑包。