【发布时间】:2014-03-10 20:29:08
【问题描述】:
我有一个安装了 Restful API 的 Codeigniter 设置。我在application->controller->api 中创建了一个 API 文件夹,之后我创建了一个如下所示的 API:
<?php
require(APPPATH.'libraries/REST_Controller.php');
class Allartists extends REST_Controller{
function artists_get()
{
if(!$this->get('artist_id'))
{
$this->response(NULL, 400);
}
$artists = $this->artist_model->get( $this->get('artist_id') );
if($artists)
{
$this->response($artists, 200);
}
else
{
$this->response(array('error' => 'Couldn\'t find any artists!'), 404);
}
}
?>
在我的application->models-文件夹中,我有一个文件artist_model.php,它看起来像这样:
<?php
Class artist_model extends CI_Model
{
function get_all_artists(){
$this->db->select('*');
$this->db->from('artists');
return $this->db->get();
}
}
?>
所以,当我输入http://localhost/myprojects/ci/index.php/api/Allartists/artists/ 时,我得到400 - Bad Request-error... 当我输入http://localhost/myprojects/ci/index.php/api/Allartists/artists/artist_id/100 时,我得到PHP 错误Undefined property: Allartists::$artist_model - 那么这里发生了什么?
【问题讨论】:
标签: php codeigniter rest