I have applied Rest server successfully as per explain in link.
Now I am trying to apply REST code in my login module. I have created new controller for login to apply REST API. My PHP code is as follows:
require APPPATH.'/libraries/REST_Controller.php';
class Login_api extends REST_Controller {
function __construct()
{
// Construct our parent class
parent::__construct();
// Configure limits on our controller methods. Ensure
// you have created the 'limits' table and enabled 'limits'
// within application/config/rest.php
$this->methods['validate_user_get']['limit'] = 500; //500 requests per hour per user/key
$this->methods['validate_user_post']['limit'] = 100; //100 requests per hour per user/key
}
function validate_user_get()
{
if(!$this->get('username') && !$this->get('password'))
{
$this->response(NULL, 400);
}
// $user = $this->some_model->getSomething( $this->get('id') );
//$user = @$users[$this->get('id')];
//$user =array($this->get('username'),$this->get('password'));
if($user)
{
$this->response($user, 200); // 200 being the HTTP response code
}
else
{
$this->response(array('error' => 'User could not be found'), 404);
}
}
function validate_user_post()
{
//$this->Login->login_user($this->input->post('username'),$this->input->post('password'));
//$this->some_model->updateUser( $this->get('id') );
//$message = array('id' => $this->get('id'), 'name' => $this->post('name'), 'email' => $this->post('email'), 'message' => 'ADDED!');
$this->response($message, 200); // 200 being the HTTP response code
}
It works fine when I print static data using get and post function. But I want to pass data in my CI_controller function from Rest controller. So what can I do for it ?
I have tried below code but not succeed :
I have write this code in Validate_user_post function :
$this->load->library('../controllers/Login');
$this->Login->login_user($this->input->post('username'),$this->input->post('password'));
Codeigniter 3.0 Session conflict with REST API
Aucun commentaire:
Enregistrer un commentaire