2016-08-12 43 views
0

我不知道爲什麼我在codeigniter 3.1.0中得到這個錯誤,我已經替換了系統,但沒有幫助。 Moldel db.php中:調用成員函數語言()null

<?php 
class DB extends CI_Controller { 
    public function show_videos($limit, $start) { 
    $sql = 'SELECT * FROM videos ORDER BY id DESC LIMIT '.$start.', '.$limit; 
    $data = $this->db->query($sql); 
    return $data->result(); 
    } 
} ?> 

這是我的控制器Home.php:

<?php 
defined('BASEPATH') OR exit('No direct script access allowed'); 

class Home 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 https://codeigniter.com/user_guide/general/urls.html 
    */ 
    public function __construct() { 
    parent::__construct(); 
    $this->load->library('pagination'); 
    $this->load->model('DB'); 
    } 

    public function index() { 
    $config['base_url'] = base_url().'/home/index'; 
    $config['total_rows'] = $this->db->count_all('videos'); 
    $config['per_page'] = 16; 
    $config['uri_segment'] = 3; 
    $choice = $config['total_rows']/$config['per_page']; 
    $config['num_links'] = floor($choice); 
    $config['full_tag_open'] = '<div class="text-center"><ul class="pagination clearfix">'; 
    $config['full_tag_close'] = '</ul></div>'; 
    $config['first_link'] = false; 
    $config['last_link'] = false; 
    $config['first_tag_open'] = '<li>'; 
    $config['first_tag_close'] = '</li>'; 
    $config['prev_link'] = '<span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>'; 
    $config['prev_tag_open'] = '<li class="prev">'; 
    $config['prev_tag_close'] = '</li>'; 
    $config['next_link'] = '<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>'; 
    $config['next_tag_open'] = '<li>'; 
    $config['next_tag_close'] = '</li>'; 
    $config['last_tag_open'] = '<li>'; 
    $config['last_tag_close'] = '</li>'; 
    $config['cur_tag_open'] = '<li class="active"><a href="#">'; 
    $config['cur_tag_close'] = '</a></li>'; 
    $config['num_tag_open'] = '<li>'; 
    $config['num_tag_close'] = '</li>'; 

    $this->pagination->initialize($config); 
    $data['page'] = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0; 
    $data['videos'] = $this->DB->show_videos($config['per_page'], $data['page']); 
    $data['pagination'] = $this->pagination->create_links(); 

     $this->load->view('header'); 
     $this->load->view('index', $data); 
    $this->load->view('footer'); 
    } 
} 

錯誤:

A PHP Error was encountered 
Severity: Notice 
Message: Undefined property: DB::$load 
Filename: libraries/Pagination.php 
Line Number: 333 
Backtrace: 
File: C:\xampp\htdocs\application\controllers\Home.php 
Line: 23 
Function: model 

File: C:\xampp\htdocs\index.php 
Line: 315 
Function: require_once 

(!) Fatal error: Call to a member function language() on null in C:\xampp\htdocs\system\libraries\Pagination.php on line 333 
Call Stack 
# Time Memory Function Location 
1 0.0004 153968 {main}() ...\index.php:0 
2 0.0011 199112 require_once('C:\xampp\htdocs\system\core\CodeIgniter.php') ...\index.php:315 
3 0.0113 886104 Home->__construct() ...\CodeIgniter.php:500 
4 0.0193 1756456 CI_Loader->model() ...\Home.php:23 
5 0.0198 1781248 CI_Controller->__construct() ...\Loader.php:353 
6 0.0198 1782120 load_class() ...\Controller.php:75 
7 0.0199 1784240 CI_Pagination->__construct() ...\Common.php:196 
A PHP Error was encountered 

Severity: Error 

Message: Call to a member function language() on null 

Filename: libraries/Pagination.php 

Line Number: 333 

Backtrace: 

如果我註釋行333函數:$ this-> CI->負載>語言( '分頁');它的工作原理,但我不知道這是解決方案。 我的默認語言是英語,我沒有任何其他語言。

+0

這裏是模型的指導http://www.codeigniter.com/user_guide/general/models.html#anatomy-of-模型和控制器http://www.codeigniter.com/user_guide/general/controllers.html#let-s-try-it-hello-world – user4419336

回答

0

一開始,模型中的第一行應該是

class DB extends CI_Model 
+0

我很愚蠢,這實際上是..謝謝! –

+0

不用擔心隊友!繼續編碼! – Pratikshya