【发布时间】:2013-05-28 08:36:27
【问题描述】:
我正在尝试为每个用户加载一个“模板”文件。
文件为每个用户加载,所以如果我有 2 个用户,它会加载两次,但是变量 $user['profileimg'] 和 $user['name'] 没有。
我不知道为什么这不起作用,而且我觉得这可能是一种不好的做法。所以我的问题是:我如何让它工作/我应该如何做这样的事情。
提前感谢您提供的任何帮助。
这是我现在得到的代码:
类:
class Cprint
{
public static function Template($name, $path = 'template')
{
include ROOT_DIR . '/' . $path . '/' . $name . '.php';
}
}
page.php
foreach($Users->getAll() as $user)
{
Cprint::Template('userlist_template');
}
userlist_template.php:
<div class="userholder">
<img class="profileimg" src="<?php echo $user['profileimg'] ?>"/>
<p><?php echo $user['name'] ?></p>
</div>
【问题讨论】:
-
$user['profileimg'] and $user['name'] does not.没有什么? -
如果我检查 html 它应该是
username
但它是 -
为什么要为每个用户加载一个模板?我想你想要做的是为每个用户加载一个看起来不同的模板?
标签: php templates variables include