【发布时间】:2014-08-01 01:46:05
【问题描述】:
如何使用包含文件中的变量,并将其用于其他包含文件?
索引
<?php
$tmp = new template($connect);
$tmp->globals('index');
$logged_in = false; //works in all included files
?>
<html>
<head>
<?php $tmp->template('head'); ?> //class method to include file
</head>
<body>
<?php echo $description; ?> //does not work either
include_head.php
<title><?php echo $title; ?></title>//does not echo anything
index_globals.php
<?php
$title="title";
$description="description";
?>
我如何参与
public function template($file){
if(isset($file) && file_exists($this->dir.$file.".php")){
ob_start();
include($this->dir.$file.".php");
$template = ob_get_contents();
return $template;
}
}
全局函数
public function globals($name){
if(isset($name) && file_exists($this->dir.$name."_globals.php")){
include($this->dir.$name."_globals.php");
}
}
【问题讨论】:
-
你是如何包含文件的?
-
你试过
echo $GLOBALS['title']吗?$description也是如此。 documentation中有一个特殊的部分 -
查看更新。我现在就试试
$GLOBALS方法——那个方法也不管用。
标签: php variables include require-once