在我的布局(Twig)中,我想从Middleware authentication中检索一个值。
如果我把,在templates.global.pĥp:
'twig' => [
'globals' => [
// Variables to pass to all twig templates
'auth' => (new \Zend\Authentication\AuthenticationService())->hasIdentity(),
],
],
并在布局 default.html.twig
{% if auth %}
Connect
{% else %}
Not connect
{% endif %}
这段代码有效,但是,它是一个好方法吗?
谢谢 :)