Php Slim框架在twig中访问flash消息

Php Slim框架在twig中访问flash消息,php,arrays,twig,slim,Php,Arrays,Twig,Slim,我正在使用Slim 3,无法访问我的小枝模板中的flash消息()。这是我的密码: 路由器: $this->flash->addMessage('msg', 'Account with ID '.$id.' has been deleted.'); return $res->withStatus(302)->withHeader('Location', '/dashboard/accounts'); {{ ["slimFlash"]["msg"][0]

我正在使用Slim 3,无法访问我的小枝模板中的flash消息()。这是我的密码:

路由器:

    $this->flash->addMessage('msg', 'Account with ID '.$id.' has been deleted.');
    return $res->withStatus(302)->withHeader('Location', '/dashboard/accounts');
{{ ["slimFlash"]["msg"][0] }}
模板:

    $this->flash->addMessage('msg', 'Account with ID '.$id.' has been deleted.');
    return $res->withStatus(302)->withHeader('Location', '/dashboard/accounts');
{{ ["slimFlash"]["msg"][0] }}
虽然我尝试打印($\u会话),但没有收到任何错误,这就是我得到的:

[slimFlash] => Array
    (
        [msg] => Array
            (
                [0] => Account with ID 1 has been deleted.
            )

    )
这就是为什么我尝试了{{[“slimFlash”][“msg”][0]},但仍然不起作用


我在这里遗漏了什么吗?

通过添加一个中间件使其正常工作

$app->add(function ($request, $response, $next) {
    $this->view->offsetSet("flash", $this->flash->getMessages());
    $response = $next($request, $response);

    return $response;
});
然后在我的模板中

{{ flash["msg"][0] }}

通过添加中间件使其正常工作

$app->add(function ($request, $response, $next) {
    $this->view->offsetSet("flash", $this->flash->getMessages());
    $response = $next($request, $response);

    return $response;
});
然后在我的模板中

{{ flash["msg"][0] }}