Codeigniter:Autoloader :: autoloader()缺少参数1

时间:2013-08-15 12:16:33

标签: php codeigniter autoloader

我一直在尝试通过在配置文件下添加自动加载功能来自动加载我的核心类,但没有结果。现在我试图让它使用钩子工作,但不幸的是同样的负面结果。当我尝试在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;
                }       
            }

        }
    } 
    ?>

1 个答案:

答案 0 :(得分:0)

尝试二维数组...

$hook['post_controller_constructor'][] = array(
                            'class'    => '',
                            'function' => 'load_config',
                            'filename' => 'load_config.php',
                            'filepath' => 'hooks'
                            );

$hook['post_controller_constructor'][] = array(
                            'class'    => '',
                            'function' => 'load_shops',
                            'filename' => 'load_shops.php',
                            'filepath' => 'hooks'
                            );  
相关问题