0
votes

When I try to load the form data in browser it shows this error

{"":"Unknown method"}

HOW TO SOLVE

This is the controller code in REST API using Codeigniter.

Help me to get out from this problem.......

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

class Api extends REST_Controller{

    public function __construct()
    {
        parent::__construct();
      //  $this->CI->lang->load('form_validation');
        $this->load->model('book_model');
        $this->load->helper('url');

    }

    public function view_get(){
        $this->load->helper('form');    

    }
    public function display_post(){
        $this->load->helper('form');
        $this->load->view('add');
    }
}

Add.php code is here, I want to display the data in webpage through the controller but when I run this code it shows an error

{"":"Unknown method"}

url: http://localhost/code-restfullAPI/index.php/API/display

<!DOCTYPE html>
<html>
<body>

<form method="POST" action="<?php site_url('index.php/Api/addBook_post'); ?>">

Name:<br>
<input type="text" name="name" >
<br>
Price:<br>
<input type="text" name="price" >
<br>
Author:<br>
<input type="text" name="author" >
<br>
Category:<br>
<input type="text" name="category" >
<br>
Language:<br>
<input type="text" name="language" >
<br>
ISBN:<br>
<input type="text" name="isbn" >
<br>
Publish Date:<br>
<input type="text" name="publish_date" >
<br>
<input type="submit" value="Add">
</form>


</body>
</html>
1
To access display, the request must be a POST request (you've literally added that, the _post part) while the browser uses GET to access URL's. - M. Eriksson
so what i need to do here for running the code in browser - user9232865
If you want to be able to access that method through the browser directly, try and define it as a GET method. Rename it to display_get() - M. Eriksson
its working but when submit the form again it shows the same error what i do, help me - user9232865
Of course. You need to decide if you should be able to access that page using POST or GET. If you need to access it through both, create two methods, one display_post() and one display_get(). I don't see why you should be able to access it through GET though, since I'm guessing it's handling the form data (which doesn't exist if you go directly to the end point)? I also don't get what your form have to do with anything. - M. Eriksson

1 Answers

0
votes

site_url('index.php/Api/addBook_post');

remove "_post" from addBook_post