【发布时间】:2016-12-22 16:35:41
【问题描述】:
我在控制器文件夹中有一个具有这种结构的项目:
- places.php
- users.php
- items.php
- ...
在我的模型文件夹中:
- Place.php(里面的名字是class Place extends ActiveRecord\Model)
- 用户.php
- ...
如果我想加载一个模型,我必须在我的控制器 places.php 中这样做:
$this->load->model('Place');
然后我必须这样调用我的方法:
$this->place->get_all_places();
它在我的本地主机上工作,但不在我的服务器上我在服务器上检查我的 php 版本,它是 5.6。
我该如何解决这个问题?
这是我的模型文件Place.php
class Place extends ActiveRecord\Model
{
static $table_name = 'places';
static $has_many = array(
);
public function get_all_places()
{
return true;
}
}
这是我的控制器文件places.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Places extends MY_Controller {
function __construct()
{
parent::__construct();
if($this->user){
$access = TRUE;
}else{
redirect('login');
}
}
function index()
{
$this->content_view = 'places/all';
}
function get_places(){
$this->theme_view = '';
$this->load->model('Place');
$this->place->get_all_places();
}
}
错误是这样的:
Unable to locate the model you have specified: place
【问题讨论】:
-
试试
$this->Place->get_all_places() -
我试过但没有用。好像不加载模型。我得到的错误信息是:无法找到您指定的模型:place
-
添加更多的控制器和模型代码,这样很难找到问题。
-
尝试从“ActiveRecord\Model”类中的“CI_Model”扩展...如果您需要使用另一种方式加载模型(自定义模型),则需要从 CI_Model 扩展:T 然后,创建它的库而不使用 CI 中的模型系统
标签: php codeigniter codeigniter-classloader