代码之家  ›  专栏  ›  技术社区  ›  lumio

CodeIgniter不会在部署计算机上加载模型

  •  0
  • lumio  · 技术社区  · 9 年前

    我用Codeigniter开发了一个小应用程序,并将其与流浪汉和Debian一起运行。一切都很好。

    所以现在我正在尝试用Xubuntu 15.04建立一个虚拟机

    现在我得到以下错误:

    Unable to locate the model you have specified: Person_model
    

    这是我加载模型的方式:

    $this->load->model('person_model');
    

    这就是我的模型在 models/person_model.php

    <?php
    
    class Person_model extends CI_Model {
      function __construct() {
        parent::__construct();
      }
    
      // ...
    }
    

    我在许邦图跑步 PHP 5.6.4-4ubuntu6.2 我在Debian上跑步 PHP 5.4.41-0+deb7u1

    感谢您的建议和帮助!

    2 回复  |  直到 9 年前
        1
  •  1
  •   kenjis    9 年前

    从CodeIgniter 3.0开始,所有类文件名(库、驱动程序、控制器和模型)必须以类似于Ucfirst的方式命名,换句话说,它们必须以大写字母开头。 http://www.codeigniter.com/user_guide/installation/upgrade_300.html#step-2-update-your-classes-file-names

    这是您必须遵循的CodeIgniter 3.0编码约定。 所以你的模型文件应该是 models/Person_model.php .

    也许你使用的是带有Vagrant共享文件夹的case insentive文件系统(主机操作系统类似于Windows或Mac)。你也不会使用Vagrant与Xubuntu共享文件夹,不是吗?

    无论如何,这是文件系统的问题,而不是PHP版本或操作系统。

        2
  •  0
  •   Abdulla Nilam    9 年前

    更改这些设置

    模型文件名应为- 个人模式.php

    然后在控制器中

    if (!defined('BASEPATH'))        exit('No direct script access allowed');
    
    class Resources extends CI_Controller
    {
        function __construct()
        {
            parent::__construct();
            $this->load->model('Person_model');
    
        }
    }
    

    还有里面 person_model.php

    if (!defined('BASEPATH'))
        exit('No direct script access allowed');
    
    class Person_model extends CI_Model {
    
        function __construct()
        {
            parent::__construct();
        }
    }
    

    这将解决您的所有问题。

    也请阅读本文

    1. CI Model
    2. CI Controller