最近我启动了宽度 Codeigniter Restful 服务器。我使用以下脚本:https ://github.com/philsturgeon/codeigniter-restserver 。
如果我试图获取模型的属性,则 Rest 服务器返回 NULL。在普通 CI 控制器中,此功能有效。代码是:
require(APPPATH.'/libraries/REST_Controller.php');
class Api extends REST_Controller
{
function user_post()
{
$username = $this->post('username');
$password = $this->post('password');
$company_code = $this->post('company_code');
$key = $this->post('key');
$this->CI =& get_instance();
// Load user model
$this->load->model('User_model');
$this->load->model('Api_model');
// Ip adres remote server
$server_ip = $_SERVER['REMOTE_ADDR'];
// Ophalen data
$user = $this->User_model->getApiLogin($username,$password);
最后一行出现错误: $user = $this->User_model->getApiLogin($username,$password);
Api 通过 Curl 调用:
$key = 'Test';
$company_code = 'econome';
$username = 'jellepals';
$password = 'test';
$curl_handle = curl_init();
curl_setopt($curl_handle, CURLOPT_URL, 'http://jelle.testapiserver.nl/api/user/format/json');
//curl_setopt($curl_handle, CURLOPT_VERBOSE, true);
//curl_setopt($curl_handle, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_handle, CURLOPT_POST, 1);
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, array(
'key' => $key,
'username' => $username,
'password' => $password));
$buffer = curl_exec($curl_handle);
curl_close($curl_handle);
$result = json_decode($buffer);
var_dump($result);
有人知道我如何在 Restserver 中调用模型函数吗?谢谢!