如何找到在 PrestaShop 中声明特殊 Smarty 变量的位置?

How to find where a special Smarty variable is declared in PrestaShop?

我使用的是 prestashop 1.6,我的 index.tpl 中有一些变量,例如 $aslist 不知道 这个变量是在哪里定义的,或者分配! 我需要找到这个变量并对其进行一些更改。 有人知道我怎样才能找到一个解决方案来显示智能变量的分配位置吗?

我需要一个地址文件,例如: $aslist.\www\controllers\front\CmsController.php - (line 58 )

中分配

您可以将此功能添加到config/config.inc.php

function log_smarty_assign($var_name)
{
    $smarty_var_filter = 'aslist';
    if ($var_name == $smarty_var_filter)
    {
        $log = '';
        $trace = debug_backtrace(false);
        if (isset($trace[1]))
        {
            $log .= 'Variable '.$var_name.' assigned in ';
            $log .= $trace[1]['file'].' #'.$trace[1]['line'];
            echo "<pre>$log</pre>";
        }           
    }
}

编辑: 应使用 $trace[1] 而不是 $trace[2]

然后搜索smarty assign方法修改成这样: 我在 /tools/smarty/sysplugins/smarty_internal_data.php

中找到了它
public function assign($tpl_var, $value = null, $nocache = false)
{
    if (is_array($tpl_var)) {
        foreach ($tpl_var as $_key => $_val) {
            if ($_key != '') {
                $this->tpl_vars[$_key] = new Smarty_variable($_val, $nocache);
                //log the assignment 
                log_smarty_assign($_key);
            }
        }
    } else {
        if ($tpl_var != '') {
            $this->tpl_vars[$tpl_var] = new Smarty_variable($value, $nocache);
            //log the assignment 
            log_smarty_assign($tpl_var);
        }
    }

    return $this;
}

输出示例:

Variable product assigned in ...\classes\controller\Controller.php #180