我一直在尝试通过在配置文件下方添加自动加载功能来自动加载我的核心类,但没有结果。现在我正在尝试使用钩子让它工作,但不幸的是同样的负面结果。当我尝试在 foreach 中输出文件路径时,我收到以下路径:
application/core/CI_Utf8.phpapplication/core/CI_URI.phpapplication/core/CI_Router.phpapplication/core/CI_Output.phpapplication/core/CI_Security.phpapplication/core/CI_Input.phpapplication/core/CI_Lang.phpapplication/core/CI_Loader.phpapplication/core/CI_DB.phpapplication/core/CI_DB.php
有人可以与我分享我做错了什么吗?提前致谢
$hook['post_controller_constructor'][] = array(
'class' => 'Autoloader',
'function' => 'register',
'filename' => 'Autoloader.php',
'filepath' => 'hooks',
'params' => array(APPPATH.'core/')
);
$hook['post_controller_constructor'][] = array(
'class' => 'Autoloader',
'function' => 'register',
'filename' => 'Autoloader.php',
'filepath' => 'hooks',
'params' => array(APPPATH.'controllers/')
);
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Autoloader {
private $_include_paths = array();
public function register(array $paths = array())
{
$this->_include_paths = $paths;
spl_autoload_register(array($this, 'autoloader'));
}
public function autoloader($class)
{
foreach($this->_include_paths as $path)
{
$filepath = $path . $class . EXT;
if(!class_exists($class, FALSE) AND is_file($filepath))
{
include_once($filepath);
echo $filepath;
break;
}
}
}
}
?>