API Problem

edited August 2014 in Modules
Tried following code for API using CI API tutorial http://code.tutsplus.com/tutorials/working-with-restful-services-in-codeigniter--net-8814 , but the error says "Fatal error: Call to undefined function find_one() in /Applications/XAMPP/xamppfiles/htdocs/cms/fuel/application/controllers/api.php on line 10" , how can i solve this? i guess the model is not loaded correctly.

<?php
require(APPPATH.'/libraries/REST.php');

class Api extends REST{
function user_get(){
if(!$this->get('id')) $this->response(NULL, 400);

$this->load->module_model(FUEL_FOLDER, 'fuel_users_model');

$user=$this->fuel_users_model>find_one(array('id'=>$this->get('id')));

print_r($user);
exit;

if($user){
$this->response($user,200);
}else{
$this->response(NULL,404);
}
}
}

Comments

  • edited August 2014
    Try using the following instead of $this:
    $CI =& get_instance(); $CI->load->module_model(FUEL_FOLDER, 'fuel_users_model'); $user=$CI->fuel_users_model->find_one(array('id'=>$this->get('id')));
  • edited 3:36PM
    Call to undefined function find_one() in /Applications/XAMPP/xamppfiles/htdocs/cms/fuel/application/controllers/api.php on line 13


    hmm, still same error
  • edited 3:36PM
    You need fuel_users_model->find_one and not fuel_users_model>find_one (note the missing "-")
  • edited 3:36PM
    solved by parent::__construct(); then load->database then do queries
Sign In or Register to comment.