我收到以下错误:
- 致命错误:调用未定义的函数getAll() ...第18行的application \ controllers \ restserver.php
- 遇到PHP错误
- 严重性:错误
- 消息:调用未定义的函数get()
- 文件名:controllers / restserver.php
- 行号:24
- 回溯:
我有以下控制器: restserver.php
defined('BASEPATH') OR exit('No direct script access allowed');
require APPPATH . '/libraries/REST_Controller.php';
class Restserver extends REST_Controller {
public function __construct() {
parent::__construct();
$this->load->database();
$this->load->helper('url');
}
public function appproviders_get() {
$this->load->model('appproviders_model');
$this->response($this->appproviders_model>getAll());
}
public function appprovider_get() {
$data = array('returned: '. $this->get('id'));
$this->load->model('appproviders_model');
$this->response($this->appproviders_model>get($data));
}
}
以下型号: appproviders_model.php
class appproviders_model extends CI_Model {
function __construct(){
parent::__construct();//Call the model constructor
}
function get($id = 0)
{
$this -> db -> select('appprovider.*');
$this -> db -> from('appprovider');
$this -> db -> join('appusers','appprovider.userID = appusers.id','left');
$this -> db -> where('appprovider.id', $id);
$query = $this -> db -> get();
if($query->num_rows()>0){
$row = $query->row();
return $row;
} else {
return NULL;
}
}
function getAll()
{
$this -> db -> select('appprovider.*, appusers.name as name');
$this -> db -> from('appprovider');
$this -> db -> join('appusers','appprovider.userID = appusers.id','left');
$this -> db -> where('appprovider.status', 1);
$query = $this -> db -> get();
if($query->num_rows()>0){
$row = $query->row();
return $row;
} else {
return NULL;
}
}
}
我正在为CodeIgniter使用以下RESTful服务器实现:
https://github.com/chriskacerguis/codeigniter-restserver
当我从浏览器调用时,知道为什么:
.../restserver/appprovider?id=1;format=json
或
.../restserver/appproviders?format=json
我收到帖子开头详细说明的错误? 它确实检测到模型而不是其功能。
必须是如此简单的事情,但我找不到错误,而且我完全疯了......
答案 0 :(得分:2)
试试这个,
你应该替换
$this->response($this->appproviders_model>getAll());
到
$this->response($this->appproviders_model->getAll());