2013-06-13 97 views
0

我对CodeIgniter非常陌生,目前正在重写我的站点以便它与CI兼容。我已经控制器文件位于/application/controllers/user.php使用CodeIgniter定位特定模型

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); 
     } 

    } 
} 

在应用程序/模型/ user.php的,我有以下几点:

namespace models; // set namespace 

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

当我把下面的网址到浏览器:

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

我接到一条错误消息:

"Fatal error: Call to a member function load() on a non-object"

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

感谢

+0

除非用户是在文件夹管理文档它将无法工作。你有$ this-> load-> model('admin/user','',true); 。但是你指定user.php位于application/models/user.php中。 – ChrisG

+0

对不起。这是一个错字。我指定了正确的位置,并与“致命错误:调用一个非对象的成员函数加载()” – Lance

回答

0

我相信你应该扩展CI_Model应用程序/模型/ user.php的

class User extends CI_Model { 

     // your codes here 
} 

下面是用笨模型http://ellislab.com/codeigniter/user-guide/general/models.html

+0

刚刚尝试过,它说:“致命错误:要求():失败打开所需'应用程序/模型/ CI_Model.php'“ – Lance

+0

最后经过一番捣鼓之后才明白。 – Lance

+0

@Lance,CI_Model类由codeigniter自动加载:) –

相关问题