Prestashop $已记录且$ is_logged

Bej*_*ols 2 php logging smarty prestashop-1.6

我遇到Smarty的问题,有时在默认代码中发生$ is_logged

.. \模块\ blockuserinfo\blockuserinfo.php

[...]
public function hookDisplayTop($params)
    {
        if (!$this->active)
            return;

        $this->smarty->assign(array(
            [...]
            'is_logged' => $this->context->customer->isLogged(),
            [...]
        ));
        return $this->display(__FILE__, 'blockuserinfo.tpl');
    }
[...]
Run Code Online (Sandbox Code Playgroud)

.. \主题\ Presta的自举\模块\ blockuserinfo \nav.tpl

<!-- Block user information module NAV  -->
{if $is_logged}
    <div class="header_user_info">
            [...]
    </div>
{/if}
Run Code Online (Sandbox Code Playgroud)

但是,只要在$ logp中更改var的名称,它就无法工作.然后它突然起作用了!怎么样?

类似的情况.

.. \主题\ Presta的自举\订单opc.tpl

<!-- Shopping Cart -->

        {include file="$tpl_dir./shopping-cart.tpl"}
        <!-- End Shopping Cart -->
        {if $is_logged AND !$is_guest}
            {include file="$tpl_dir./order-address.tpl"}
        {else}
            <!-- Create account / Guest account / Login block -->
            {include file="$tpl_dir./order-opc-new-account.tpl"}
            <!-- END Create account / Guest account / Login block -->
Run Code Online (Sandbox Code Playgroud)

只有当我用$ logged替换$ is_logged时才能正常工作.这两种情况都不会产生错误,只是获得FALSE值并给出意想不到的结果.

我应该在哪里找原因?

Ser*_*e P 9

让我们说清楚,一步一步,$logged$is_logged刚刚Smarty的变量,这意味着他们的某处定义.

我不确定你使用的是什么版本,在blockuserinfo.php的1.6.0.11中我看到了:

this->smarty->assign(array( ... 'logged' => $this->context->customer->isLogged(),

从在另一侧的类/控制器/ Frontcontroller.phpinit()方法可能会看到:

'is_logged' => (bool)$this->context->customer->isLogged(),

然后在下面:

// Deprecated $this->context->smarty->assign(array( ... 'logged' => $this->context->customer->isLogged(),

两个结论如下:

  1. 在更好地使用的全局代码中$is_logged,$logged可能会在下一版本中删除.
  2. 如果变量重新定义,它将覆盖全局值(是的,我是Captain Obvious).

您可以检查很容易例如,通过像"XXX"和"YYY",然后在你的一些虚拟值replasing FrontController变量nav.tpl一样{$is_logged} = {$logged}.

希望它能帮助你更好地了解情况.