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

时间:2015-08-30 16:48:23

标签: php codeigniter

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

所以现在我尝试使用Xubuntu 15.04设置虚拟机。安装相同的软件包(PHP作为Apache模块)

现在我收到以下错误:

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();
  }

  // ...
}

在Xubuntu上我运行 PHP 5.6.4-4ubuntu6.2 ,在Debian上运行 PHP 5.4.41-0 + deb7u1

感谢您的任何建议和帮助!

2 个答案:

答案 0 :(得分:1)

  

从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共享文件夹使用案例提交文件系统(主机操作系统类似于Windows或Mac)。并且你不会在Xubuntu上使用Vagrant共享文件夹,不是吗?

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

答案 1 :(得分:0)

更改这些设置

模型文件名应为 - person_model.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