douershuang7356 2015-06-05 08:41
浏览 26
已采纳

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

I using prestashop 1.6 and I have some variable in my index.tpl like as $aslist that I Don't know where this variable is defined or assigned! I need to find this variable and do some change over that. anybody know how can I find a solution that show where smarty variables assigned ?

I need to a address file like as: $aslist assigned in .\www\controllers\front\CmsController.php - (line 58 )

  • 写回答

1条回答 默认 最新

  • drb0901500211 2015-06-05 14:25
    关注

    You can add this function to 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>";
            }           
        }
    }
    

    Edit: $trace[1] should be used instead of $trace[2]

    And then search for the smarty assign method and modify it to something like this: I found it in /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;
    }
    

    Output example:

    Variable product assigned in ...\classes\controller\Controller.php #180
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办