我有一个类,它访问静态变量,方法stuff_field
将它们放入tplItms::$replacements
数组。
<?php
require_once "../src/acesse.inc.php";
require_once "../src/members/memberPage.inc.php";
$page_class = (isset($_SESSION['acesse_member']) && $_SESSION['acesse_member']) ? "memberPage" : "acessePage";
$p = new $page_class('{lang[Welcome-VServices]}', 'shell.tpl');
$t = new tpl('home_shell.tpl');
$top = ($page_class == 'memberPage') ? '' : tpl::translateTpl('hometop');
$t->stuff_field('php', 'HomeTop', $top);
$t->stuff_field('php', 'Home', tpl::translateTpl('home'));
$p->tpl->stuff_field('php', 'Content', $t->get_markup());
if (false) { // servicebox displayer code, for posterity
$p = new $page_class('{lang[Welcome-VServices]}', 'shell.tpl');
$db = new vservdb();
$db->query("SELECT title AS ServiceName, primary_url AS ServiceURL FROM vservices WHERE display=1 ORDER BY listing_priority DESC, title");
$t = new tpl('servicebox.tpl');
while($r = $db->nextrow()) {
$t_clone = clone $t;
$page = $r['ServiceName']=="V-Newswire" ? '/index.php' : '';
$r['ServiceURL'] = $r['ServiceURL'] .$page.'?lang='.$_SESSION['lang'];
$t_clone->stuff_php($r);
$markup .= $t_clone->get_markup();
}
$p->tpl->stuff_php('Content', "<div class=\"centered\">$markup</div>");
}
print_r(tplItms::$replacements);
echo $p->display();
当我执行上面示例中的print_r()
时,所有预期的项都在数组中。但是,如果我将print_r()
移到display()
方法中,所有项目都会消失,为什么?
这是显示方法:
public function display($template, $field = null, $value = null, $value2 = null, $end = false){
print_r(tplItms::$replacements);
if(empty($template))
return false;
$ad = new tpl($template, null, $end);
if($field)
$ad->stuff_field($field, $value, $value2);
$ad->setup();
return $ad->get_markup();
}
如果有帮助,这里是tplItms
类:
class tplItms{
public static $replacements = array();
}
为什么他们走了?我能做什么才不会消失?我无法真正修改display()
参数,因为有1,000个页面使用此display()
方法