我在使用app.session.flashbag.get('notice')
.
在我制作的控制器中
public function updateAction(Request $request, $id)
{
$em = $this->getDoctrine()->getManager();
$entity = $em->getRepository('SomeBundle:SomeEntity')->find($id);
$editForm = $this->createForm(new SomeEntityType(), $entity);
$editForm->bind($request);
if ($editForm->isValid()) {
$em->persist($entity);
$em->flush();
$flash = $this->get('translator')->trans('Some Entity was successfully updated');
$this->get('session')->getFlashBag()->add('notice', $flash);
return $this->redirect($this->generateUrl('some_entity_edit', array('id' => $id)));
}
在 editAction 中,我从会话中获取信息:
public function editAction($id)
{
$em = $this->getDoctrine()->getManager();
$flashes = $this->get('session')->getFlashBag()->get('notice', array());
//...
//...
return array(
'entity' => $entity,
'edit_form' => $editForm->createView(),
'flashes' => $flashes
);
}
我正在尝试在 TWIG 中从会话中获取信息:
TWIG: {% for flashMessage in app.session.flashbag.get('notice') %}{{ flashMessage }}{% endfor %}
PHP: {% for flashMessage2 in flashes %}{{ flashMessage2 }}{% endfor %}
app.session.flashbag.get('notice') 是空的,flash 有一个值。
您有什么想法,为什么我无法从 app.session.flashbag.get('notice') 获取数据?