douzhimao8656 2013-12-20 06:42
浏览 61

Ubuntu上的Codeigniter没有加载模型

I've recently switched from Windows 7 to Ubuntu.. Now I'm having this strange problem with codeigniter.. My code works prefect on Widnows 7 Xampp server, but when I try to access it on ubuntu having apache2, I cannot load any model, libraries etc.

Here is my code for model

<?php
class Usermodel extends CI_Model
{
    function __construct()
    {
        // Call the Model constructor
       parent::__construct();
       $this->user_per_page = 8;
    }

    function getUser($id)
    {
    $query = $this->db->query("SELECT * FROM user WHERE id = $id");
    if(intval($query->num_rows()) > 0)
    {
        $data = $query->result();
        return $data[0];
    }
    else
        return null;
    }
}

Here is the code of my controller where i am loading model

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

class Register extends CI_Controller 
{   
    public function index()
    {
        $this->load->model("Usermodel");
        $fb_config = array(
            'appId'  => 'xxxxxxxxxxx',
            'secret' => 'xxxxxxxxxxxxxxxxxxxxxxxx'
        );

        $this->load->library('facebook', $fb_config);
        $this->load->helper('security');
    }
}

I've already tried the following

1. Changed usermodel.php to Usermodel.php 2. Changed $this-load->model("Usermodel") to $this-load->model("usermodel")

but none seem to work

I get this fatal error when i call $this->Usermodel->getUser(1) in index() function of my controller

PHP Fatal error: Call to a member function getUser() on a non-object in /var/www/voicebuds/application/controllers/register.php on line 19, referer: mysite

UPDATE If i put the Usermodel in config/autoload.php, it works fine.. So I must say there is some problem with loader function.

  • 写回答

3条回答 默认 最新

  • douwei1944 2013-12-20 06:50
    关注

    check your model file name for model

    <?php
    // file name usermodel.php
    class Usermodel extends CI_Model
    {
        function __construct()
        {
            // Call the Model constructor
           parent::__construct();
           $this->user_per_page = 8;
        }
    
        function getUser($id)
        {
        $query = $this->db->query("SELECT * FROM user WHERE id = $id");
        if(intval($query->num_rows()) > 0)
        {
            $data = $query->result();
            return $data[0];
        }
        else
            return null;
        }
    }
    

    in your controller load appropriate model using model file name

    <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
    
    class Register extends CI_Controller 
    {   
        public function index()
        {
            $this->load->model("usermodel");//your file name of model
            $fb_config = array(
                'appId'  => '454005957970086',
                'secret' => '7b8e9664cb0439f88da00007996278c7'
            );
    
            $this->load->library('facebook', $fb_config);
            $this->load->helper('security');
        }
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog