【问题标题】:An uncaught Exception was encountered Type: RuntimeException Message: Unable to locate the model you have specified: Events遇到未捕获的异常类型:RuntimeException 消息:无法找到您指定的模型:事件
【发布时间】:2018-06-12 01:14:38
【问题描述】:

错误

遇到未捕获的异常类型:RuntimeException 消息: 找不到您指定的模型:事件文件名: /home/dailysurvive/public_html/citymallgulberglahore.com/mall/system/core/Loader.php 行号:344 回溯:文件: /home/dailysurvive/public_html/citymallgulberglahore.com/mall/application/controllers/Welcome.php 行:29 功能:模型文件: /home/dailysurvive/public_html/citymallgulberglahore.com/mall/index.php 行:315 功能:require_once

错误文件的图片如下

模型.php

defined('BASEPATH') OR exit('No direct script access allowed');

/**
 * Model Class
 *
 * @package     CodeIgniter
 * @subpackage  Libraries
 * @category    Libraries
 * @author      EllisLab Dev Team
 * @link        https://codeigniter.com/user_guide/libraries/config.html
 */
class CI_Model {

/**
 * Class constructor
 *
 * @return  void
 */
public function __construct()
{
    log_message('info', 'Model Class Initialized');
}

// --------------------------------------------------------------------

/**
 * __get magic
 *
 * Allows models to access CI's loaded classes using the same
 * syntax as controllers.
 *
 * @param   string  $key
 */
public function __get($key)
{
    // Debugging note:
    //  If you're here because you're getting an error message
    //  saying 'Undefined Property: system/core/Model.php', it's
    //  most likely a typo in your model code.
    return get_instance()->$key;
}

}

加载器.php

    $model = ucfirst($model);
    if ( ! class_exists($model, FALSE))
    {
        foreach ($this->_ci_model_paths as $mod_path)
        {
            if ( ! file_exists($mod_path.'models/'.$path.$model.'.php'))
            {
                continue;
            }

            require_once($mod_path.'models/'.$path.$model.'.php');
            if ( ! class_exists($model, FALSE))
            {
                throw new RuntimeException($mod_path."models/".$path.$model.".php exists, but doesn't declare class ".$model);
            }

            break;
        }

        if ( ! class_exists($model, FALSE))
        {
            throw new RuntimeException('Unable to locate the model you have specified: '.$model);
        }
    }
    elseif ( ! is_subclass_of($model, 'CI_Model'))
    {
        throw new RuntimeException("Class ".$model." already exists and doesn't extend CI_Model");
    }

    $this->_ci_models[] = $name;
    $CI->$name = new $model();
    return $this;
}

Welcome.php

public function index($data=null)
{
    //$this->load->view('welcome_message');
   $this->load->model("events");
   $data['records'] = $this->events->getAllRecords();


    $this->load->view('header',$data);
    $this->load->view('home',$data);
    $this->load->view('footer',$data);

}

function home()
{
    $data = array(
        'back_step' => '../',
    );


    $dat = array(

        'email'     => $this->input->post('email')
    );



    $this->load->model("events");
    $this->load->database();

   $res = $this->db->insert('subscribe',$dat);

    $data['records'] = $this->events->getAllRecords();

    $this->index($data);

index.php

/*
 * --------------------------------------------------------------------
 * LOAD THE BOOTSTRAP FILE
 * --------------------------------------------------------------------
 *
 * And away we go...
 */
require_once BASEPATH.'core/CodeIgniter.php';

【问题讨论】:

  • 问题还在吗??

标签: php codeigniter web codeigniter-2 codeigniter-3


【解决方案1】:

1:将模型名称从 Events.php 重命名为 Events_model.php 2:使用$this->load->model('Events_model', 'events')

【讨论】:

  • 仍然面临同样的问题
  • 你能把你的项目目录和控制器和模型文件的截图贴出来吗?
  • 对不起,这是 event.php 的代码load->database(); $this->db->order_by("id", "desc"); $q = $this->db->get("事件"); if($q->num_rows() > 0) { return $q->result(); } 返回数组(); } } ?>
  • 类名必须是 Events_model extends CI_Model
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-03-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多