【问题标题】:Only variable should be passed by referenced in Magento problem在 Magento 问题中,只能通过引用传递变量
【发布时间】:2010-12-15 10:52:44
【问题描述】:

为了在生成的 html 源代码中查看模板路径以进行调试,我在

中使用了以下代码 sn-p

app/code/core/Mage/Core/Block/Template.php

/**
 * Render block
 *
 * @return string
 */
public function renderView()
{
    $this->setScriptPath(Mage::getBaseDir('design'));
    $showDebug = true;
    if (!$showDebug) {
        $html = $this->fetchView($this->getTemplateFile());
    }
    else {
        $template = $this->getTemplateFile();
        $tagName = 'template_'.current(explode('.',end(explode('/',$template))));
        $html = '<'.$tagName.'><!-- '.$template.' -->';
        $html .= $this->fetchView($template);
        $html .= '<!--/ '.$template.' --></'.$tagName.'>';
    }
    return $html;
}

但现在在错误日志中我看到以下内容: 2010-12-13T21:55:35+00:00 ERR (3): 严格注意:只有变量应该在 /app/code/core/Mage/Core/Block/Template.php 第 245 行通过引用传递

应该如何引用它以避免这个错误?

【问题讨论】:

    标签: php debugging magento


    【解决方案1】:

    很确定你的问题是这一行

    $tagName = 'template_'.current(explode('.',end(explode('/',$template))));
    

    endcurrent 方法接受数组变量作为参数,通过引用传递。您正在传递 PHP 不喜欢的函数调用的结果。假设 sn-p 正在尝试获取无扩展名的模板名称,请尝试使用此方法

    $parts  = pathinfo($template);
    $tagName    = $parts['filename']; 
    

    【讨论】:

    • @Alan 这行得通。并且错误消失了。当你说假设 sn-p 试图获得一个无扩展名的模板名称时,我不太理解你的意思。
    • 模板名称:“foo/baz/bar.html”。模板名称:“bar.html”。无扩展名的模板名称:“bar”
    • 唯一的问题是这种方法会导致管理员的某些部分在编辑 cms 页面时正确显示
    • @capnhud:当您在系统的某个部分使用该功能时,该功能并非设计用于使用,就会发生类似的事情。
    • 在模板提示中,是否有另一种方法可以获得类似的结果?
    【解决方案2】:

    改为安装开发者工具栏扩展。或者从管理员打开模板提示。

    【讨论】:

    • 这个 sn-p 的好处是它允许您查看生成的 html 并准确查看正在调用的模板,而模板提示显示了覆盖,但是您需要保留页面打开以便返回到有问题的模板。
    猜你喜欢
    • 1970-01-01
    • 2013-06-21
    • 2011-05-27
    • 1970-01-01
    • 2013-05-21
    • 1970-01-01
    • 2012-12-24
    相关资源
    最近更新 更多