0

I am trying to send data through url like

http://localhost/api/index.php/society/?date=20/04/2017&s_name=ssr

but it's showing error message:

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

When I am testing with postman or advance rest client application, it's working fine and data is posting and updating database.

url: http://localhost/api/index.php/society

My Controller....

<?php

defined('BASEPATH') OR exit('No direct script access allowed');

require_once APPPATH . 'libraries/REST_Controller.php';

use Restserver\Libraries\REST_Controller;

class Society extends REST_Controller
{

    function __construct()
    {
        parent::__construct();
        $this->load->database(); 
        $this->load->model('Society_model');
    }

    public function index_get()
    {
        $data = $this->Society_model->society_get();
        $this->response($data);
    }

    public function index_post()
    {

        $data = array( 
            'date' =>$this->post('date'),
            'society_name' => $this->post('s_name'), 
            'society_group' => $this->post('g_name'),
            'contact_name' => $this->post('c_name'),
            'mobile_no' => $this->post('mobile'),
            'address' => $this->post('address'),
            'city' => $this->post('city'),
            'state' => $this->post('state'),
            'pincode' => $this->post('pincode'),
            'email_id' =>$this->post('email')
           ); 

         $this->Society_model->insert($data); 

         $this->set_response($data, REST_Controller::HTTP_CREATED);
    }
}

My Model....

<?php

class Society_model extends CI_Model
{

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

    public function society_get(){
        $this->db->select('*');
        $this->db->from('society_contact');
        $result = $this->db->get();
        return $result->result();
    }

    public function insert($data) 
    { 
         if ($this->db->insert("society_contact", $data)) 
         { 
            return true; 
         } 
    } 
}
n4m31ess_c0d3r
  • 3,028
  • 5
  • 26
  • 35
Guljar Prasad
  • 101
  • 2
  • 8
  • Can you post the code you think it should be running, as well as anything which would cause it to return the "Unknown Method" response? – gabe3886 Apr 20 '17 at 09:03
  • I have poted my codes can you check ? @gabe3886 – Guljar Prasad Apr 20 '17 at 11:47
  • Is you `Society` controller stored straight in the `controllers` folder or is it in a sub-folder? Plus you need to URL encode your parameters. Your date parameter has `/` which is also used as a URL delimiter. – Hicaro Apr 21 '17 at 11:37
  • Society stored in controller not having sub folder. how can i encode URL in parameters? I am new in REST API field development in codeigniter. @ Hicaro – Guljar Prasad Apr 21 '17 at 12:57

2 Answers2

0

society is your model function name ..call it by index name http://localhost/api/index.php/index/?date=20/04/2017&s_name=ssr

Rajat Gupta
  • 342
  • 2
  • 12
0

You can't use the POST method via a browser. You must use POSTMAN or another REST Client. URL in browser only allows you to GET information.

Please refer to this post How do I manually fire HTTP POST requests with Firefox or Chrome?

Also your URL http://localhost/api/index.php/society/?date=20/04/2017&s_name=ssr

it is not correct because when you added ?something=something, this is a parameter, also if you added / this are separate parts of the url. That is why you are getting Unknow Method.

YakovL
  • 7,557
  • 12
  • 62
  • 102
rfcabal
  • 121
  • 1
  • 4
  • 17