2014-03-05 30 views
0

當我試圖擴展CI_Model時,我對codeigniter和MVC很新,我有一個致命錯誤。 我做它像例子可以點是我錯了:codeigniter錯誤當我擴展CI_Model

class Site extends CI_Controller { 

     public function index(){ 
      echo "hi internet <br>"; 
      $this->hello(); 
      $this->addStuff(); 
     } 

     public function hello(){ 
      echo " H E L L O <br>"; 
     } 

     public function addStuff(){ 
      echo "math <br>"; 
      $this->load->model("math"); 
      echo $this->Math->add(3,8); 
     } 
    } 
    class Math extends CI_Model { 

     public function add($num1,$num2){ 
      return $num1+$num2; 
     } 

     public function sub($num1,$num2){ 
      return $num1+$num2; 
     } 

    } 

我的錯誤是:

Fatal error: Class 'application\models\CI_Model' not found 
in C:\projects \CodeIgniter\application\models\Math.php on line 12 line 12 is class 
Math extends CI_Model line 
+0

可能重複:類'CI \ _Model'not found](http://stackoverflow.com/questions/12503783/fatal-error-class-ci-model-not-found) –

+0

我不會延長模型 – user3041833

+0

class Math延長CI_Model – user3041833

回答

0
應用

/controllers- 創建site.php文件 -

class Site extends CI_Controller { 

     public function index(){ 
      echo "hi internet <br>"; 
      $this->hello(); 
      $this->addStuff(); 
     } 

     public function hello(){ 
      echo " H E L L O <br>"; 
     } 

     public function addStuff(){ 
      echo "math <br>"; 
      $this->load->model("math"); 
      echo $this->Math->add(3,8); 
     } 
    } 

in application/models create math.php文件

class Math extends CI_Model { 

     public function add($num1,$num2){ 
      return $num1+$num2; 
     } 

     public function sub($num1,$num2){ 
      return $num1+$num2; 
     } 

    } 
0

你必須做出site.php控制器,並使用類似的

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

class Site extends CI_Controller 
{ 
} 

和型號就可以使site_model.php和使用像[致命錯誤的認爲

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

class Site_Model extends CI_Model 
{ 
}