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 working with 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
What I have tried:
<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() {
$r = $this->user_model->read();
$this->response($r);
}
public function user_put() {
$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 is written in model
public function read() {
$query = $this->db->query("select * from `tbl_user`");
return $query->result_array();
}
I am getting error like this mentioned
{"status":false,"error":"Unknown method"}
this the link for image getting error.
https://i.stack.imgur.com/ykktL.png