Codeigniter模型未加载,没有错误


Codeigniter model not loading with no errors

我的Codeigniter模型没有加载,我没有得到任何错误。当我尝试使用$this->load->模型('All_sensor_data')。什么也不会发生。我不知道发生了什么事。我试过改变文件名,类名等。

BTW,该日志消息永远不会到达。我可以删除$this->load->模型('all_sensor_data'),然后日志消息工作。

My Base Model:

<?php
//Filename: application/core/my_model.php
class MY_Model extends CI_Model {
    const DB_TABLE = 'abstract';
    const DB_TABLE_PK = 'abstract';
    /**
     * Create record.
     */
    private function insert() {
        $this->db->insert($this::DB_TABLE, $this);
        $this->{$this::DB_TABLE_PK} = $this->db->insert_id();
    }
    /**
     * Update record.
     */
    private function update() {
        $this->db->update($this::DB_TABLE, $this, $this::DB_TABLE_PK);
    }
    /**
     * Populate from an array or standard class.
     * @param mixed $row
     */
    public function populate($row) {
        foreach ($row as $key => $value) {
            $this->$key = $value;
        }
    }
    /**
     * Load from the database.
     * @param int $id
     */
    public function load($id) {
        $query = $this->db->get_where($this::DB_TABLE, array(
                $this::DB_TABLE_PK => $id,
            ));
        $this->populate($query->row());
    }
    /**
     * Delete the current record.
     */
    public function delete() {
        $this->db->delete($this::DB_TABLE, array(
                $this::DB_TABLE_PK => $this->{$this::DB_TABLE_PK},
            ));
        unset($this->{$this::DB_TABLE_PK});
    }
    /**
     * Save the record.
     */
    public function save() {
        if (isset($this->{$this::DB_TABLE_PK})) {
            $this->update();
        }
        else {
            $this->insert();
        }
    }
    /**
     * Get an array of Models with an optional limit, offset.
     *
     * @param int $limit Optional.
     * @param int $offset Optional; if set, requires $limit.
     * @return array Models populated by database, keyed by PK.
     */
    public function get($limit = 0, $offset = 0) {
        if ($limit) {
            $query = $this->db->get($this::DB_TABLE, $limit, $offset);
        }
        else {
            $query = $this->db->get($this::DB_TABLE);
        }
        $ret_val = array();
        $class = get_class($this);
        foreach ($query->result() as $row) {
            $model = new $class;
            $model->populate($row);
            $ret_val[$row->{$this::DB_TABLE_PK}] = $model;
        }
        return $ret_val;
    }
} 

我的模型:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
//filename: application/models/all_sensor_data.php
class All_sensor_data extends MY_Model {
    const DB_TABLE = "all_sensor_data";
    const DB_TABLE_PK = 'id';
    /**
     * All_Sensor_Data primary key
     * @var int
     */
    public $id;
    /**
     * Sensor Name
     * @var string
     */
    public $name;
    /**
     * Defines the type of sensor. e.g. LIGHT, MOISTURE, TEMPERATURE
     * @var string
     */
    public $type;
    /**
     * Date the row was added
     * @var
     */
    public $modify_date;
    /**
     * Value read from the sensor
     * @var int
     */
    public $value;
    /**
     * Describes the section where the sensor is located.
     * @var
     */
    public $section;
}

这是我的控制器:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * Created by PhpStorm.
 * User: James
 * Date: 6/24/14
 * Time: 9:25 PM
 */
class Incoming extends CI_Controller
{
    function __construct() {
        parent::__construct();
        $this->load->model('All_sensor_data');
    }
    public function index() {
       echo "Hello, Incoming Controller";
    }
    public function incomingSensorData($sensor, $value)
    {
        log_message('info', __CLASS__ . ' ' . __LINE__ . ' ' .  'Hello Incoming Data');
    }
}
日志输出:
DEBUG - 2014-07-07 22:59:14 --> Hooks Class Initialized
DEBUG - 2014-07-07 22:59:14 --> Utf8 Class Initialized
DEBUG - 2014-07-07 22:59:14 --> UTF-8 Support Enabled
DEBUG - 2014-07-07 22:59:14 --> URI Class Initialized
DEBUG - 2014-07-07 22:59:14 --> Router Class Initialized
DEBUG - 2014-07-07 22:59:14 --> Output Class Initialized
DEBUG - 2014-07-07 22:59:14 --> Security Class Initialized
DEBUG - 2014-07-07 22:59:14 --> Input Class Initialized
DEBUG - 2014-07-07 22:59:14 --> Global POST and COOKIE data sanitized
DEBUG - 2014-07-07 22:59:14 --> Language Class Initialized
DEBUG - 2014-07-07 22:59:49 --> Config Class Initialized
DEBUG - 2014-07-07 22:59:49 --> Hooks Class Initialized
DEBUG - 2014-07-07 22:59:49 --> Utf8 Class Initialized
DEBUG - 2014-07-07 22:59:49 --> UTF-8 Support Enabled
DEBUG - 2014-07-07 22:59:49 --> URI Class Initialized
DEBUG - 2014-07-07 22:59:49 --> Router Class Initialized
DEBUG - 2014-07-07 22:59:49 --> Output Class Initialized
DEBUG - 2014-07-07 22:59:49 --> Security Class Initialized
DEBUG - 2014-07-07 22:59:49 --> Input Class Initialized
DEBUG - 2014-07-07 22:59:49 --> Global POST and COOKIE data sanitized
DEBUG - 2014-07-07 22:59:49 --> Language Class Initialized
DEBUG - 2014-07-07 22:59:49 --> Loader Class Initialized
DEBUG - 2014-07-07 22:59:49 --> Helper loaded: url_helper
DEBUG - 2014-07-07 22:59:49 --> Database Driver Class Initialized
DEBUG - 2014-07-07 22:59:49 --> Controller Class Initialized
DEBUG - 2014-07-07 22:59:49 --> CI_Model Class Initialized
DEBUG - 2014-07-07 23:00:50 --> Config Class Initialized
DEBUG - 2014-07-07 23:00:50 --> Hooks Class Initialized
DEBUG - 2014-07-07 23:00:50 --> Utf8 Class Initialized
DEBUG - 2014-07-07 23:00:50 --> UTF-8 Support Enabled
DEBUG - 2014-07-07 23:00:50 --> URI Class Initialized
DEBUG - 2014-07-07 23:00:50 --> Router Class Initialized
DEBUG - 2014-07-07 23:00:50 --> Output Class Initialized
DEBUG - 2014-07-07 23:00:50 --> Security Class Initialized
DEBUG - 2014-07-07 23:00:50 --> Input Class Initialized
DEBUG - 2014-07-07 23:00:50 --> Global POST and COOKIE data sanitized
DEBUG - 2014-07-07 23:00:50 --> Language Class Initialized
DEBUG - 2014-07-07 23:00:50 --> Loader Class Initialized
DEBUG - 2014-07-07 23:00:50 --> Helper loaded: url_helper
DEBUG - 2014-07-07 23:00:50 --> Database Driver Class Initialized
DEBUG - 2014-07-07 23:00:50 --> Controller Class Initialized
DEBUG - 2014-07-07 23:00:50 --> CI_Model Class Initialized

您是否正确地制作了您的模型,即

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); 
class All_sensor_data extends CI_Model
{
 // Your functions here
}

并将您的模型命名为all_sensor_date.php,并将其放在ci的models文件夹中。

现在,如果你在控制器中调用它,它肯定会工作。

关于错误报告,转到您的主index.php文件,即在与ci中的应用程序文件夹相同的目录中,检查定义的环境,确保它设置为development以报告所有错误。

EDIT:

这里有错误$this->load->model('All_sensor_data');//您已经在这里使用类名来加载您的模型

用这个代替

$this->load->model('all_sensor_data');//文件名用于加载模型