Php 只有变量应通过Magento问题中的引用进行传递
为了在生成的html源代码中查看模板的路径以便调试,我在 app/code/core/Mage/core/Block/Template.phpPhp 只有变量应通过Magento问题中的引用进行传递,php,debugging,magento,Php,Debugging,Magento,为了在生成的html源代码中查看模板的路径以便调试,我在 app/code/core/Mage/core/Block/Template.php /** * Render block * * @return string */ public function renderView() { $this->setScriptPath(Mage::getBaseDir('design')); $showDebug = true; if (!$showDebug) {
/**
* 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;
}
/**
*渲染块
*
*@返回字符串
*/
公共函数renderView()
{
$this->setScriptPath(Mage::getBaseDir('design');
$showDebug=true;
如果(!$showDebug){
$html=$this->fetchView($this->getTemplateFile());
}
否则{
$template=$this->getTemplateFile();
$tagName='template_'。当前(分解('',结束(分解('/',$template)));
$html='';
$html.=$this->fetchView($template);
$html.='';
}
返回$html;
}
但现在在错误日志中,我看到了以下内容:
2010-12-13T21:55:35+00:00错误(3):严格注意:只有变量才能通过第245行的/app/code/core/Mage/core/Block/Template.php中的引用传递
如何引用此项以避免此错误?请改为安装开发人员工具栏扩展。或者打开管理员提供的模板提示。非常确定您的问题是这一行
$tagName = 'template_'.current(explode('.',end(explode('/',$template))));
和方法接受数组变量作为参数,通过引用传递。您正在传递函数调用的结果,这是PHP不喜欢的。假设该代码段试图获取一个无扩展名的模板名,请改为尝试此操作
$parts = pathinfo($template);
$tagName = $parts['filename'];
此代码段的好处是,它允许您查看生成的html并准确查看调用的模板,而模板提示显示了一个覆盖,但是您需要保持页面打开,以便重新引用有问题的模板。@Alan这是可行的。错误消失了。当你说假设代码段试图获得一个无扩展名的模板名称时,我不太明白你的意思。模板名称:“foo/baz/bar.html”。模板名称:“bar.html”。一个无扩展名的模板名:“bar”唯一的问题是,这种方法会导致管理员的某些部分在编辑cms时正确显示page@capnhud:当您在系统的某个部分中使用某个功能时,该功能不是设计用来使用的,诸如此类的事情将会发生。在模板提示的作用下,有没有其他方法可以获得类似的结果?