小编Nic*_*rev的帖子

Symfony 2.1 app.session.flashbag.get('something')返回空值

我使用时遇到了麻烦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)));

    }
Run Code Online (Sandbox Code Playgroud)

在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
    );
}
Run Code Online (Sandbox Code Playgroud)

我正在尝试TWIG从会话中获取信息:

TWIG: {% for flashMessage in app.session.flashbag.get('notice') %}{{ flashMessage }}{% endfor …
Run Code Online (Sandbox Code Playgroud)

php session symfony

1
推荐指数
1
解决办法
1万
查看次数

标签 统计

php ×1

session ×1

symfony ×1