Hello everyone I am working on REST API in Codeigniter but i am surprise in normal codeigniter when we give method name after controller for example(localhost/project_name/controller/user_get) it will get all users from table but while working with REST API in Codeigniter I am getting unknown method error please tell me how to define method name while rest api in form action
below i have written my code
in view page when i want to click button in form it should call method and retrieve all users
<form method="post" action="<?=base_url('index.php/Api/user_get')?>">
<button>Click Here</button>
</form>
controller code
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
require(APPPATH . '/libraries/REST_Controller.php');
class Api extends REST_Controller {
public function __construct() {
parent::__construct();
$this->load->model('user_model');
}
public function user_get() { //this method will get all users from table
$r = $this->user_model->read();
$this->response($r);
}
public function user_put() { //this method will insert users details
$id = $this->uri->segment(3);
$data = array('name' => $this->input->get('user_name'),
'pass' => $this->input->get('user_password'),
'type' => $this->input->get('user_type')
);
$r = $this->user_model->update($id, $data);
$this->response($r);
}
}
Below code written in model
public function read() {
$query = $this->db->query("select * from `tbl_user`");
return $query->result_array();
}
Getting error like this