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 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀