我希望在我的网站中有一个header.php文件。目前,我有以下几点:在函数中包含的文件中使用变量
的header.php
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="<?php if(isset($depth)){echo $depth;};?>css/style.css">
的functions.php
function include_layout_template($template="", $depth="")
{
global $depth;
include(SITE_ROOT.DS.'public'.DS.'layouts'.DS.$template);
}
的index.php
<?php include_layout_template('header.php', "../"); ?>
但是$深度dissappears,我甚至不能echo $ depth;它只是空白。我怎样才能得到在header.php中使用的深度变量?
$深度既是全局变量又是函数'include_layout_template'的参数?那一定是搞砸了...... – Yaniro