2013-03-01 08:09
浏览 46

在Codeigniter Restful服务器中加载模型功能

Recently i started width Codeigniter Restful server. I use the following script: https://github.com/philsturgeon/codeigniter-restserver.

If i trying to get a property of my model, the Rest server returns NULL. In a normal CI controller this function works. The code is:

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

        // Ip adres remote server
        $server_ip  = $_SERVER['REMOTE_ADDR'];

        // Ophalen data
        $user = $this->User_model->getApiLogin($username,$password);

The error eccors on the last line: $user = $this->User_model->getApiLogin($username,$password);

The Api is called through 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);  
         $result = json_decode($buffer);  

Does somebody know how i can call a model function in a Restserver? Thanks!

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

2条回答 默认 最新

  • dongwen1935 2013-03-01 13:08

    I think the problem is in my db connexion. Someone build an extra layer betweeen db class and the model called Db_handler.php. When calling from the api this layer doesn,t work apparently. With this layer we can use multiple databases. When adding this:

       var $db;
        public function __construct() {
            $this->db = $this->load->database($this->config->item('default', 'database'), TRUE);

    To my model the connexxion works fine.

    Thanks for rhe comment MDeSilva.

    解决 无用
    打赏 举报

相关推荐 更多相似问题