使用CodeIgniter定位特定的模型


Location a specific model with CodeIgniter

我对CodeIgniter非常陌生,目前正在重写我的一个站点,以便它与CI兼容。控制器文件位于/application/controllers/user.php

if(!defined('BASEPATH')) 
{
    exit('No direct script access allowed');
} else
{   
    class user extends CI_Controller 
    {
        public function index() 
        {   
            $this->load->library('customautoloader');
            $this->load->model('user', '', true);   

            $data = array('title' => 'Title goes here',
                        'body' => 'The string to be embedded here!');
            $this->load->library('template');
            $this->template->load('default', null, $data);
        }
    }   
}

在application/models/user.php中,我有如下的

namespace models; // set namespace
if(! defined('BASEPATH')) 
{
    exit('No direct script access allowed'); 
} else
{
    class User
    {   
         ...
    }
 }

当我在浏览器中输入以下url时:

http://localhost:8888/CodeIgniter/user/

我看到一个错误信息,上面写着:

"致命错误:在非对象上调用成员函数load() "

我知道这可能是一个简单的问题,但我对CI和它使用的规则非常陌生。

谢谢

我认为你应该在application/models/user.php中扩展CI_Model

 class User extends CI_Model {
        // your codes here
 }

下面是使用Codeigniter模型的文档http://ellislab.com/codeigniter/user-guide/general/models.html