我的代码类似于以下内容。我从db获取模板并将其分配给框架对象。奇怪的是,当检查模板变量是否设置时,isset总是返回false。在
echo $framework->getSys()->template;
甚至打印变量的内容。如何解释这种行为,更重要的是,我如何解决总是分配默认模板的问题?
if (isset($_SESSION['login'])) { // isset works like expected
$result = $framework->getSys()->db->query("SELECT t.name FROM users AS u, templates AS t WHERE u.id = '".$_SESSION['id']."' AND u.template = t.id LIMIT 1") or die(mysqli_error($framework->getSys()->db));
if ($result) {
while($obj = $result->fetch_object()) {
$framework->getSys()->template = $obj->name;
}
}
}
if (!isset($framework->getSys()->template)) {
echo $framework->getSys()->template; // This prints the template from the db
$framework->getSys()->template = "default";
}