使用php在多个文件夹上自动加载多个文件?
如何自动加载可能存储在多个文件夹中的多个文件? 我已经做的就像在图片上展示的: 在Index.php[init.php]创建所需的文件,该文件包含:使用php在多个文件夹上自动加载多个文件?,php,autoload,Php,Autoload,如何自动加载可能存储在多个文件夹中的多个文件? 我已经做的就像在图片上展示的: 在Index.php[init.php]创建所需的文件,该文件包含: <?php spl_autoload_register(function ($class){ require_once "classes/class.$class.php"; }); 当@dan miller注释提到检查文件是否存在时,问题得到了解决,然后每个新文件夹都需要检查文件 <?php spl_autoload_re
<?php
spl_autoload_register(function ($class){
require_once "classes/class.$class.php";
});
当@dan miller注释提到检查文件是否存在时,问题得到了解决,然后每个新文件夹都需要检查文件
<?php
spl_autoload_register(function ($class){
$filename="classes/$class.php";
if(!file_exists($filename))
{
return "file : $filename is not Exist on the Given Path";
}
require_once "classes/$class.php";
});
spl_autoload_register(function ($class){
$filename="conf/$class.php";
if(!file_exists($filename))
{
return "file : $filename is not Exist on the Given Path";
}
require_once "conf/$class.php";
});
使用PSR-4自动加载程序(它随composer一起提供)@tereško你能举个例子吗?你可以使用spl_autoload_register注册另一个自动加载函数
你说得对,那实际上是行不通的。它应该检查文件是否存在。也许可以检查这个问题: