【问题标题】:Fatal error: Class 'Model' not found in CodeIgniter致命错误:在 CodeIgniter 中找不到类“模型”
【发布时间】:2013-06-30 15:38:45
【问题描述】:

我的 CI 版本是 CI2.3。我在本地主机上运行this php code。我按照那里给出的所有步骤进行操作,但出现此错误,不知道为什么?我将控制器更改为 CI_Controller。 Hello world Program 工作得很好。此链接代码不起作用。请需要帮助!

【问题讨论】:

  • 您可以按照第一个提供的内容进行操作。可能你是 CI 的新手。并研究规则ellislab.com/codeigniter/user-guide
  • 什么 2.3 版本?最新版本仅为 2.1.3。 @Damien 什么人?
  • @KarSho 我指的是 OP 链接的代码,而不是您链接的手册。

标签: php mysql codeigniter codeigniter-2 fatal-error


【解决方案1】:

你应该在 codeIgniter 中像这样扩展模型

class Modelname extends CI_Model
  {
   function __construct()
    {
          parent::__construct();
    }
  }

【讨论】:

    【解决方案2】:

    实际上,学习指南是 CI 的旧版本,您曾经在其中从 Model 类扩展模型,如指南中所示。但现在它已经改变了。现在您必须从 CI_Model 扩展它,Controller 也是如此。

    对于控制器

    class Employee_controller extends CI_Controller
    {
      //load the constructor
      function __construct()
      {
        //inherit the parent constructor
        parent::__construct();
      }
    }
    

    对于模型:

    class Employee_model extends CI_Model
    {
      //load the constructor
      function __construct()
      {
        //inherit the parent constructor
        parent::__construct();
      }
    }
    

    【讨论】:

      【解决方案3】:

      这样使用

      <?php
      
      class Employee_model extends CI_Model
      {
           //load the constructor
           function __construct()
           {
                //inherit the parent constructor
                parent::__construct();
           }
      }
      

      【讨论】:

        【解决方案4】:

        您必须在模型文件夹中创建一个model,例如my_model.php

        并创建class 喜欢

        class My_model extends CI_Model
        {
           function __construct()
           {
              parent::__construct();
           }
        }
        

        记住class 和file 应该相同。

        文档http://ellislab.com/codeigniter/user-guide/general/models.html

        【讨论】:

          猜你喜欢
          • 2015-07-01
          • 2013-11-04
          • 2015-04-29
          • 2013-02-18
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2014-10-03
          相关资源
          最近更新 更多