ファイルには多くのindex.php
インクルード ファイルがあり、これらのインクルード ファイルの一部には、インクルードされたファイルに属するいくつかの変数があります。index.php
「インクルード コード」をindex.php
ファイルに書き込むか、ファイルにインクルードされたすべての個別のファイルに「インクルード コード」を挿入することはできindex.php
ますか? 私が書いたものを理解するのは難しいかもしれませんが、ここに私のフォルダとコードがあります:
私のフォルダとファイルはここにあります:
/
|
+ includes/
| |
| + initialize.php
| + functions.php
| + config.php
|
+ layouts/
| |
| + header.php
| + sidebar.php
| + content.php
| + footer.php
|
+ images/
| |
| + image1.jpg
|
+ index.php
私のinitialize.phpはここにあります:
//initialize.php
<?php
defined('DS') ? null : define('DS', '/');
defined('SITE_ROOT') ? null :
define('SITE_ROOT', '/webspace/httpdocs');
defined('LIB_PATH') ? null : define('LIB_PATH', SITE_ROOT.DS.'includes');
require_once(LIB_PATH.DS.'config.php');
require_once(LIB_PATH.DS.'functions.php');
?>
ここに function.php があります
//function.php
<?php
function include_layout_template($template="") {
include(SITE_ROOT.DS.'layouts'.DS.$template);
}
function __autoload($class_name) {
$class_name = strtolower($class_name);
$path = LIB_PATH.DS."{$class_name}.php";
if(file_exists($path)) {
require_once($path);
} else {
die("The file {$class_name}.php could not be found.");
}
}
?>
ここに content.php の一部があります
//content.php
<img src="<?php echo SITE_ROOT.DS.'images'.DS.'image1.jpg' ?>" />
index.php は次のとおりです。
//index.php
<?php require_once "includes/initialize.php";?>
<?php include_layout_template("index_header.php"); ?>
<?php include_layout_template("sidebar.php"); ?>
<?php include_layout_template("index_content.php"); ?>
<?php include_layout_template("footer.php"); ?>
だから、私の問題は、 content.php のコードです:
<img src="<?php echo SITE_ROOT.DS.'images'.DS.'image1.jpg' ?>" />
動作しません。ファイルが定数を認識しないため、サイトに画像がありませSITE_ROOT
ん。DS
initialize.php が含まれていないのでわかります。function.phpにはインクルードはありませんがDS
、SITE_ROOT
動作します。initialize.phpは index.php に含まれていますが、includes の下のファイルにこれらSITE_ROOT
とDS
. includes フォルダーにファイルを挿入すると、 index.php<?php require_once "includes/initialize.php";?>
に多くの initialize.php が存在します。
1 つのファイルに 1つだけを使用<?php require_once "includes/initialize.php";?>
することで、この問題をどのように解決できますか? または、より良いデザインはどうですか。