最近、幅の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 でモデル関数を呼び出す方法を知っている人はいますか? ありがとう!