__尛Zou゜ 发表于 2013-11-6 11:12:53

CI加载不到model层 这是少了什么配置?我的CI版本是2.1.4的

model层:
class News_model extends CI_Model
{
       
       
        public function __construct(){
                parent::__construct();
                $this->load->database();
        }
       
       
       
        public function take_news()
        {
                $query=$this->db->get('news');
                return $query->row_array();
        }
}


控制器:
class Welcome extends CI_Controller {

        /**
       * Index Page for this controller.
       *
       * Maps to the following URL
       *                 http://example.com/index.php/welcome
       *        - or -
       *                 http://example.com/index.php/welcome/index
       *        - or -
       * Since this controller is set as the default controller in
       * config/routes.php, it's displayed at http://example.com/
       *
       * So any other public methods not prefixed with an underscore will
       * map to /index.php/welcome/<method_name>
       * @see http://codeigniter.com/user_guide/general/urls.html
       */
       
        publicfunction __construct()
        {
                $this->load->model('News_model');
        }
       
        public function index()
        {
                $data['a'] = '变量测试输出';
            $data['b'] = '案例拉倒辣的了卡的林科大辽阔的';   
               
            $data=$this->news_model->take_news();
            var_dump($data);
                $this->load->view('welcome_message.html',$data);
        }
}


视图输出:
A PHP Error was encounteredSeverity: Notice
Message: Undefined property: Welcome::$load
Filename: controllers/welcome.php
Line Number: 23


Fatal error: Call to a member function database() on a non-object in D:\wamp\www\htdocs\CodeIgniter\application\controllers\welcome.php on line 23



跋锋寒 发表于 2013-11-6 11:55:00

控制器

publicfunction __construct()
{
   parent::__construct();
   $this->load->model('news_model');
}

__尛Zou゜ 发表于 2013-11-6 12:06:05

解决了 3Q网上版本各有不同啊最后还是像你说的这样谢谢

wwwhx110com 发表于 2013-11-6 20:47:56

大小写的问题

莫名奇妙 发表于 2013-11-6 21:15:26

自定义的__construct()没有调用parent的

燃雲 发表于 2013-11-7 21:11:33

算得上进阶讨论?大开眼界!
页: [1]
查看完整版本: CI加载不到model层 这是少了什么配置?我的CI版本是2.1.4的