hansonfox 发表于 2011-10-19 16:45:22

调用模型中函数的问题

在控制器中调用模型中的函数,出现了如下错误:
Fatal error:Call to a member function fir() on a non-object in E:\xampp\htdocs\CI\application\controllers\allview.php on line 12
模型是加载过的,为什么无法调用函数呢?

baiyuxiong 发表于 2011-10-19 17:14:05

贴代码

hansonfox 发表于 2011-10-19 18:02:20

controller:
class Allview extends CI_Controller{
      
      function _construct(){
            parent::_construct();
            $this->load->model('Allview_model',TRUE);
      }
      
      function index(){
            
            $fir_data = $this->Allview_model->fir();

model:
class Allview_model extends CI_Model{
      
      function _construct(){
            parent::_construct();
      }
      
      functionfir(){
            $sql = 'SELECT * FROM person WHERE flag = ? ';
            return $this->db->query($sql,'1');
            $this->db->close();
      }

hansonfox 发表于 2011-10-19 19:40:39

:L 找到问题了~
$this->load->model('Allview_model',TRUE);
这行model()里第二个参数应该是别名,第三个才应该是自动加载database的 "TRUE"。
$this->load->model('Allview_model','',TRUE);
这样就对了.......
页: [1]
查看完整版本: 调用模型中函数的问题