最近我启动了width 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);
通过Curl调用Api:
             $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中调用模型函数吗?谢谢!
发布于 2013-03-01 21:08:05
我想问题出在我的数据库连接上。有人在db类和名为Db_handler.php的模型之间建立了一个额外的层。当从api调用时,这一层显然不起作用。有了这一层,我们可以使用多个数据库。添加此命令时:
   var $db;
    public function __construct() {
        parent::__construct();
        $this->db = $this->load->database($this->config->item('default', 'database'), TRUE);
    }对我的模型来说,connexxion工作得很好。
谢谢你的评论,MDeSilva。
https://stackoverflow.com/questions/15153208
复制相似问题