我想创建一个函数来包含请求的文件。我想这个函数来听,如果我需要/ require_once,包括/ include_once创建我自己的文件包含功能
所以它会看起来像
<?php
myFile(FILE, REQO); // REQO meaning require_once
?>
到目前为止,我已经创建功能,包括文件:
define("HEADER", "header.php");
define("FOOTER", "footer.php");
function myFile($file) {
if (file_exists($file)) {
include $file;
} else {
die($file." does not exit");
}
return $file;
}
所以当我在我的“模板”文件中使用此功能
<?php
myFile(HEADER);
echo "some text";
myFile(FOOTER);
?>
它工作正常,但我想扩展myFile();按我描述的方式运作。任何人都可以建议如何
第二个参数中的switch/case'? – Darren
为什么你不能只使用require_once(“文件名”)? – Forbs
使用** spl-autoload-register **。这里有很多指导。这真的很好用。 –