Welcome Guest, Not a member yet? Register   Sign In
Code Igniter RESTful Modeling and Controller
#1

[eluser]Unknown[/eluser]
I have been developing using non framework for about 3 years and I have heard about PHP framework codeigniter. Thanks for this great framework man!

But,...

I think I missed something using this framework which is used for API for my mobile application.

I've facing some problem to get data from database using Phil's CI framework, RESTful plugin. My browser shows error code:

Code:
{"status":false,"error":"Unknown method."}

Using my logic below:

controller: user.php

Code:
<?php

  require(APPPATH.'libraries/REST_Controller.php');

  class User extends REST_Controller{

  public function user_get()  
  {  
    //IF USER NOT EXIST
    if(!$this->get('id'))
    {
        $this->response(NULL, 400);
    }

    //CHECK TO MODEL FUNCTION
    $user = $this->user_model->get_user($this->get('id'));

    //IF USER EXIST
    if($user)
    {
        $this->response($user, 200); // 200 being the HTTP response code
    }
}  

   public function user_put()  
   {  
    // create a new user and respond with a status/errors  
   }  

   public function user_post()  
   {  
    // update an existing user and respond with a status/errors  
   }  

   public function user_delete()  
   {  
    // delete a user and respond with a status/errors  
   }  
}
?>

model: user_model.php

Code:
<?php

    class User_model extends CI_Model{

    function __construct() {
        parent::__construct();        
    }

    function get_user($id){
        $query = $this->db->get('mt_user', array('idmt_user'=>$id));
        return $query->row_array();
    }

   }
   ?>

i'm accessing the database which is has this rows:

Code:
idmt_user,username,password, emails, createdate

accessed using mozilla:
Code:
http://localhost/<project>/index.php/user/<userid>

Where's the error(s) ?

thanks.

update, i am already defined the autoloads for database. But this problem still persist. Is there any helps? thanks

as stated below in answer, i tried to access the url, /user/get_user/ but still showing the same result. Is there any problem using idmt_user in database?




Theme © iAndrew 2016 - Forum software by © MyBB