有没有办法用一些“不区分大小写的标志”来调用require_once? 在Windows中没关系,但linux区分大小写。有没有办法覆盖? 感谢
答案 0 :(得分:2)
当然,加载
strtolower($className . ".php")
并将文件命名为小写。
无论您如何尝试加载文件,都只会加载小写版本。
答案 1 :(得分:0)
每次加载时都可以使用它自动加载相应的类。你必须改变目录取决于你的项目。你可以使用echo或print_r打印每次调用时加载的类。所有类名都必须具有相同的格式,例如className.class.php,例如Dashboard.class.php,Category.class.php。您可以使用 用来制作第一个字母的资本。
function __autoload($className)
{
if (file_exists(__DIR__ . '/../library/' . strtolower($className) . '.class.php'))
{
require_once(__DIR__ . '/../library/' . strtolower($className) . '.class.php');
}
else if (file_exists(__DIR__ . '/../application/controllers/' . strtolower($className) . '.php'))
{
require_once(__DIR__ . '/../application/controllers/' . strtolower($className) . '.php');
}
else if (file_exists(__DIR__ . '/../application/models/' . strtolower($className) . '.php'))
{
require_once(__DIR__ . '/../application/models/' . strtolower($className) . '.php');
}
}
答案 2 :(得分:0)
只需在header.php或其他一些常见文件中包含其他内容。
<?php
$filename = basename($_SERVER['SCRIPT_FILENAME']);
$request = basename($_SERVER['SCRIPT_NAME']);
if($filename != $request)
die('Case of filename and request do not match!');
?>
我认为这可以帮助您解决问题。另请参阅以下位置https://superuser.com/questions/431342/linux-both-case-sensitive-and-case-insensitive-and-always-inconvenient