首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >代码点火器不允许通过url在REST方法中发布数据。它的错误就像未知的方法

代码点火器不允许通过url在REST方法中发布数据。它的错误就像未知的方法
EN

Stack Overflow用户
提问于 2017-04-20 07:14:58
回答 2查看 2.6K关注 0票数 0

我试图通过url发送数据,就像

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

但它显示了错误信息:

{“状态”:假,“错误”:“未知方法”}

当我使用postmanadvance rest client应用程序进行测试时,它运行得很好,而且数据正在发布和更新数据库。

网址:http://localhost/api/index.php/society

我的控制器.

代码语言:javascript
复制
<?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);
    }
}

我的模型.

代码语言:javascript
复制
<?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; 
         } 
    } 
}
EN

Stack Overflow用户

发布于 2017-04-20 14:12:28

society是您的模型函数名..call it by index name http://localhost/api/index.php/index/?date=20/04/2017&s

票数 0
EN
查看全部 2 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43512670

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档