需要您的
PHP模板帮助.我是新来的
PHP(我来自Perl Embperl).无论如何,我的问题很简单:
>我有一个小模板来渲染一些项目,让它成为博客文章.
>我知道使用这个模板的唯一方法是使用’include’指令.
>我想把这个模板称为循环,通过所有相关的博文.
>问题:我需要传递一个参数到这个模板;在这种情况下,引用表示博客文章的数组.
代码看起来像这样:
$rows = execute("select * from blogs where date='$date' order by date DESC");
foreach ($rows as $row){
print render("/templates/blog_entry.php", $row);
}
function render($template, $param){
ob_start();
include($template);//How to pass $param to it? It needs that $row to render blog entry!
$ret = ob_get_contents();
ob_end_clean();
return $ret;
}
任何想法如何完成这个?我真的很抱歉:)有没有其他方法来渲染模板?