繁体   English   中英

使用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
    {   
         ...
    }
 }

当我将以下网址放入浏览器时:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM