PHP自动加载can';不要使用其他文件夹

PHP自动加载can';不要使用其他文件夹,php,Php,我上课有问题。我有3个文件夹,分别称为1、2和3。one文件夹的功能类似于控制器、two模型和two视图。我在two文件夹(模型层)中创建了自动加载类,但我无法调用其他类。我的autoload.php文件如下所示: <?php function __autoload($class){ include 'two/'.$class .'.php'; } spl_autoload_register('__autoload'); 使用spl\u autoload\u寄存器可以注册多个

我上课有问题。我有3个文件夹,分别称为
1
2
3
one
文件夹的功能类似于控制器、
two
模型和
two
视图。我在
two
文件夹(模型层)中创建了自动加载类,但我无法调用其他类。我的autoload.php文件如下所示:

<?php

function __autoload($class){
    include 'two/'.$class .'.php';
}

spl_autoload_register('__autoload');

使用
spl\u autoload\u寄存器
可以注册多个自动加载器。但第一种方法是注册自动加载器,检查其中一个文件夹中是否存在
$class.php
one
two
twree
),并将其包括在内

spl_autoload_register(function ($className) {
    $folders = ['one', 'two', 'three'];

    foreach ($folders as $folder) {
        if (file_exists($path = $folder. '/'.$className .'.php')) {
            include $path;
            break;
        }
    }
});

但这也是一个有问题的方法。如果在
one
two
目录中都有
Foo
类,该怎么办?你想进口什么?要解决这些冲突,可以使用并遵循。

的指令,使用
spl\u autoload\u register
可以注册多个自动加载器。但第一种方法是注册自动加载器,检查其中一个文件夹中是否存在
$class.php
one
two
twree
),并将其包括在内

spl_autoload_register(function ($className) {
    $folders = ['one', 'two', 'three'];

    foreach ($folders as $folder) {
        if (file_exists($path = $folder. '/'.$className .'.php')) {
            include $path;
            break;
        }
    }
});
但这也是一个有问题的方法。如果在
one
two
目录中都有
Foo
类,该怎么办?你想进口什么?要解决这些冲突,可以使用,并遵循的指令