【发布时间】:2015-01-13 09:55:06
【问题描述】:
我对 Joomla 3 的一个 3rd 方组件有疑问。不幸的是,我不是高级 php 开发人员,组件所有者目前不支持此功能,所以我完全靠我自己 =)
提前 - 我已经阅读了那里的所有相关主题,但无法以正确的方式完成。
我的问题是转换这一行:
return preg_replace('/\{([a-zA-Z_]+)\}/e', '$item->\\1', $this->rowtemplate);
使用 preg_replace_callback(),因为在 php 5.5 /e 参数已被弃用。
非常感谢。
编辑:
有完整的代码部分:
public function loadRowtemplate ($item)
{
$table = $this->params->get('table');
if(!$this->rowtemplate) {
$rowtemplate = $table['row'][0] ? "<td><p>" . nl2br($table['row'][0]) . "</p></td>" : "";
$rowtemplate .= $table['row'][1] ? "<td><p>" . nl2br($table['row'][1]) . "</p></td>" : "";
$rowtemplate .= $table['row'][2] ? "<td><p>" . nl2br($table['row'][2]) . "</p></td>" : "";
$rowtemplate .= $table['row'][3] ? "<td><p>" . nl2br($table['row'][3]) . "</p></td>" : "";
$rowtemplate .= $table['row'][4] ? "<td><p>" . nl2br($table['row'][4]) . "</p></td>" : "";
$this->rowtemplate = str_replace(",", "<br/>", $rowtemplate);
}
**return preg_replace('/\{([a-zA-Z_]+)\}/e', '$item->\\1', $this->rowtemplate);**
}
编辑 2:
Harold Prins Extension (com_profiler) 使用 PHP 5.5 为 Joomla 3 和 Profiler 提供了正确的工作解决方案:
return preg_replace_callback(
'/\{([a-zA-Z_]+)\}/',
function ($match) use ($item) {
if (isset($item->{$match[1]})) {
return $item->{$match[1]};
}
return "";
},
$this->rowtemplate
);
非常感谢 Matteo Tassinari 的解决方案。
【问题讨论】:
-
你能告诉我们rowtemplate在替换之前的样子吗?
-
它之前的设置为 protected $rowtemplate = "";
-
@Jack - 阅读手册后我无法做到这一点。这是我的主题。我不是开发人员,对此感到抱歉...
-
你肯定尝试过什么;手册页提供了三个您可以使用的示例......不是开发人员并不意味着“只发布一个'give meh teh codez'问题”
-
在过去的 1 小时里,我从这里和官方 PHP 网站上玩了很多例子,但在问之前没有成功。我不是在尝试之前先问的人。
标签: php preg-replace joomla3.0 joomla-extensions