用户
 找回密码
 入住 CI 中国社区
搜索
查看: 2897|回复: 3
收起左侧

[HELP] 调用模型中函数的问题

[复制链接]
发表于 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
模型是加载过的,为什么无法调用函数呢?
发表于 2011-10-19 17:14:05 | 显示全部楼层
贴代码
 楼主| 发表于 2011-10-19 18:02:20 | 显示全部楼层
controller:
PHP复制代码
class Allview extends CI_Controller{
       
        function _construct(){
            parent::_construct();
            $this->load->model('Allview_model',TRUE);
        }
       
        function index(){
           
            $fir_data = $this->Allview_model->fir();
 
复制代码

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


 楼主| 发表于 2011-10-19 19:40:39 | 显示全部楼层
找到问题了~
PHP复制代码
$this->load->model('Allview_model',TRUE);
复制代码

这行model()里第二个参数应该是别名,第三个才应该是自动加载database的 "TRUE"。
PHP复制代码
$this->load->model('Allview_model','',TRUE);
复制代码

这样就对了.......

本版积分规则