Php 我如何在细枝中获得Cookie值?

Php 我如何在细枝中获得Cookie值?,php,twig,Php,Twig,我有登录表单,我想在注销按钮上更改它。 以下是代码: <nav class="flex"> {% if app.request.cookies.get('user') == NULL %} {% embed "Backend/loginForm.php" %} {% endembed %} {% endif %} {% if app.request.cookies.get('user') != NUL

我有登录表单,我想在注销按钮上更改它。 以下是代码:

<nav class="flex">
        {% if app.request.cookies.get('user') == NULL %}
        {% embed "Backend/loginForm.php" %}

        {% endembed  %}
        {% endif %}
        {% if app.request.cookies.get('user') != NULL %}
            {{"logged"}}
        {% endif %}
    <div class="btn searchBtn" id="searchBtn">
        SEARCH
    </div>
</nav>

{%if app.request.cookies.get('user')==NULL%}
{%embed“Backend/loginForm.php”%}
{%endembed%}
{%endif%}
{%if app.request.cookies.get('user')!=NULL%}
{{“已记录”}
{%endif%}
搜寻

Cookie['user']已设置,但app.request.cookies.get('user')始终返回FALSE。我做错了什么?

您使用的是symfony/silex吗?我这里没有使用任何框架。我需要使用symfony来做这件事,或者没有应用程序可以做吗?
app.request
是symfony提供的是。你可以模仿它,但是如果你不使用frameworkTwig,它只是一个模板系统,它对cookie或其他东西一无所知。渲染模板时需要将其作为数据注入。设置TWIG全局变量并在if中使用是否是一个好主意?或者更好的方法是使用symfony?我想指出,我还不知道如何使用框架。