PHP 自动加载器和 Unix 区分大小写的文件系统
我有 index.php
<?php
include('_controller/Autoloader.php');
Gold_Autoloader::init();
$mysql = new Gold_MySQL();
_controller/Autoloader.php
<?php
class Gold_Autoloader
{
public static $loader;
public static function init()
{
if (self::$loader == NULL)
self::$loader = new self();
return self::$loader;
}
public function __construct()
{
spl_autoload_register(array($this, 'controller'));
spl_autoload_register(array($this, 'resources'));
}
public function resources($className)
{
$className = preg_replace('#Gold_#', '', $className);
$className = preg_replace('#_#', DIRECTORY_SEPARATOR, $className);
set_include_path(PROJECT_ROOT . '_resources');
spl_autoload_extensions('.php');
spl_autoload($className);
}
public function controller($className)
{
$className = preg_replace('#Gold_#', '', $className);
$className = preg_replace('#_#', DIRECTORY_SEPARATOR, $className);
set_include_path(PROJECT_ROOT . '_controller');
spl_autoload_extensions('.php');
spl_autoload($className);
}
}
并且我有带有 Gold_MySQL.class 的文件 _controller/MySQL.php 。 在 Windows 系统上,此代码可以工作,包括 MySQL.php,但在托管此代码时不起作用((
[Thu Jan 27 12:55:57 2011] [error] PHP Fatal error: Class 'Gold_MySQL' not found in /home/u91167/youd0main.com/www/index_.php on line 5
编辑
如何使 Unix 可以查看任何文件?Zend 没有带有小写字母的文件。
I have index.php
<?php
include('_controller/Autoloader.php');
Gold_Autoloader::init();
$mysql = new Gold_MySQL();
_controller/Autoloader.php
<?php
class Gold_Autoloader
{
public static $loader;
public static function init()
{
if (self::$loader == NULL)
self::$loader = new self();
return self::$loader;
}
public function __construct()
{
spl_autoload_register(array($this, 'controller'));
spl_autoload_register(array($this, 'resources'));
}
public function resources($className)
{
$className = preg_replace('#Gold_#', '', $className);
$className = preg_replace('#_#', DIRECTORY_SEPARATOR, $className);
set_include_path(PROJECT_ROOT . '_resources');
spl_autoload_extensions('.php');
spl_autoload($className);
}
public function controller($className)
{
$className = preg_replace('#Gold_#', '', $className);
$className = preg_replace('#_#', DIRECTORY_SEPARATOR, $className);
set_include_path(PROJECT_ROOT . '_controller');
spl_autoload_extensions('.php');
spl_autoload($className);
}
}
And I have file _controller/MySQL.php with Gold_MySQL.class.
On windows system this code is working and including MySQL.php, but on hosting this code not working ((
[Thu Jan 27 12:55:57 2011] [error] PHP Fatal error: Class 'Gold_MySQL' not found in /home/u91167/youd0main.com/www/index_.php on line 5
EDIT
How to make so that Unix could look at any files? Zend has no files with a lowercase letter.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
听起来您的文件名区分大小写,并且您尝试以错误的大小写加载文件。即您可能需要
gold_mysql.php
而不是Gold_MySql.php
?Sounds like your filename is case sensitive and you're trying to load a file in the wrong case. i.e. you might need
gold_mysql.php
instead ofGold_MySql.php
?这听起来像是服务器文件系统的区分大小写的问题。
检查路径和文件名的大小写是否正确。
linux/unix 关心大小写。
Windows 没有。
注意:这回答了问题的先前版本
It sounds like a case sensitive problem with the server filesystem.
check paths and filenames for correct case.
linux/unix take care about case.
windows does not.
note: This answers a previous version of the question
可能是您覆盖了包含路径。在你的index.php中尝试类似的方法
并删除Autoloader类中的set_include_path()调用。
恕我直言,如果您使用 Zend Framework,最好编写两个分隔符自动加载器并将它们推送到 Zend 的自动加载器堆栈。
It could be that you're overriding the include path. In your index.php try something like
And remove the set_include_path() calls in your Autoloader class.
IMHO, If you are using Zend Framework, it would be better to write two separator autoloaders and push them to Zend's autoloader stack.