【发布时间】:2013-11-20 10:12:00
【问题描述】:
我是 CodeIgniter 的新手,并按照 Nettuts 高级教程学习如何在 codeigniter 中构建 CMS。
首先,我的 application 和 system 目录位于 public_html 之外的不同路径上,并在 config.php 文件中设置路径。
我创建了两个文件 Frontend_Controller.php 和 Admin_Controller.php 并在这些文件中创建了如下类。
application/My_Controller.php
class MY_Controller extends CI_Controller
{
public $data = array();
function __construct()
{
parent::__construct();
$this->data['errors'] = array();
$this->data['site_name'] = config_item('site_name');
}
}
库/Frontend_Controller.php
class Frontend_Controller extends MY_Controller
{
function __construct()
{
parent::__construct();
}
}
库/Admin_Controller.php
class Admin_Controller extends MY_Controller
{
function __construct()
{
parent::__construct();
}
}
现在,当我尝试通过将 __autoload() 函数写入 config.php 文件来自动加载上述类时,但它不会加载文件/类
config.php
function __autoload($classname)
{
if(strpos($classname, 'CI_' !== 0))
{
$file = APPPATH . 'libraries/' . $classname . '.php';
if(file_exists($file) && is_file($file))
{
@include_once($file);
}
}
}
谁能帮我理解和解决这个问题...非常感谢
【问题讨论】:
-
为什么不使用 CI 的自动加载?为什么要在配置中加载类??
-
哦!我不太了解它。你能教我怎么做吗?
-
您阅读文档了吗?挺好的,相信会回答你的问题的。作为个人建议,您应该在使用之前阅读框架/库文档...
-
是的,我已经阅读了文档并需要在 autoload.php 中定义,但我仍然很困惑如何编写类名以及在哪里编写?因为我在库中有控制器类也有大写的文本。
标签: php codeigniter