Php 遇到未捕获的异常,调用未定义的方法

Php 遇到未捕获的异常,调用未定义的方法,php,web-services,codeigniter,codeigniter-3,Php,Web Services,Codeigniter,Codeigniter 3,我犯了这个错误,连续三天都在试图找出什么地方出了问题,但运气不佳: 遇到未捕获的异常 类型:错误 消息:调用未定义的方法Nsbh::post() 文件名:application\controllers\nsbh.php 电话号码:25 nsbh.php <?php Class Nsbh extends CI_Controller{ var $API =""; function __construct() { parent::__construct();

我犯了这个错误,连续三天都在试图找出什么地方出了问题,但运气不佳:

遇到未捕获的异常

类型:错误

消息:调用未定义的方法Nsbh::post()

文件名:application\controllers\nsbh.php

电话号码:25

nsbh.php

<?php
Class Nsbh extends CI_Controller{

    var $API ="";

    function __construct() {
        parent::__construct();
        $this->API="http://localhost/rest_ci/index.php";
        $this->load->library('session');
        $this->load->library('curl');
        $this->load->helper('form');
        $this->load->helper('url');
    }


    function index(){
        $data['datansbh'] = json_decode($this->curl->simple_get($this->API.'/nsbh'));
        $this->load->view('nsbh/list',$data);
    }


    function create(){
        if(isset($_POST['submit'])){
            $data = array(
                    'id'           => $this->post('id'),
                    'name'          => $this->post('name'),
                    'location'    => $this->post('location'),
                    'tgl'    => $this->post('tgl'),
                    'addrs'    => $this->post('addrs'));
            $insert =  $this->curl->simple_post($this->API.'/nsbh', $data, array(CURLOPT_BUFFERSIZE => 10)); 
            if($insert)
            {
                $this->session->set_flashdata('hasil','Insert Succeed');
            }else
            {
               $this->session->set_flashdata('hasil','Insert Failed');
            }
            redirect('nsbh');
        }else{

            $this->load->view('nsbh/create');
        }
    }


    function edit(){
        if(isset($_POST['submit'])){
            $data = array(
                    'id'           => $this->input->post('id'),
                    'name'          => $this->input->post('name'),
                    'location'    => $this->input->post('location'),
                    'tgl'    => $this->input->post('tgl'),
                    'addrs'    => $this->input->post('addrs'));
            $update =  $this->curl->simple_put($this->API.'/nsbh', $data, array(CURLOPT_BUFFERSIZE => 10)); 
            if($update)
            {
                $this->session->set_flashdata('hasil','Update Succeed');
            }else
            {
               $this->session->set_flashdata('hasil','Update Failed');
            }
            redirect('nsbh');
        }else{
            $params = array('id'=>  $this->uri->segment(3));
            $data['datansbh'] = json_decode($this->curl->simple_get($this->API.'/nsbh',$params));
            $this->load->view('nsbh/edit',$data);
        }
    }


    function delete($id){
        if(empty($id)){
            redirect('nsbh');
        }else{
            $delete =  $this->curl->simple_delete($this->API.'/nsbh', array('id'=>$id), array(CURLOPT_BUFFERSIZE => 10)); 
            if($delete)
            {
                $this->session->set_flashdata('hasil','Deleted');
            }else
            {
               $this->session->set_flashdata('hasil','Failed');
            }
            redirect('nsbh');
        }
    }
}

在构造函数中添加
$this->load->library('form_validation')

因此,您的构造函数如下所示:

function __construct() {
    parent::__construct();
    $this->API="http://localhost/rest_ci/index.php";
    $this->load->helper('form');
    $this->load->helper('url');
    $this->load->library('session');
    $this->load->library('curl');
    $this->load->library('form_validation');
}

在构造函数中添加
$this->load->library('form_validation')

因此,您的构造函数如下所示:

function __construct() {
    parent::__construct();
    $this->API="http://localhost/rest_ci/index.php";
    $this->load->helper('form');
    $this->load->helper('url');
    $this->load->library('session');
    $this->load->library('curl');
    $this->load->library('form_validation');
}

您在'id'=>$this->post('id')中缺少输入

因此,正确的代码如下所示:

'id' => $this->input->post('id')

您还必须在所有其他位置使用输入。

您在'id'=>$this->post('id')中缺少输入

因此,正确的代码如下所示:

'id' => $this->input->post('id')
您还必须在所有其他位置使用输入。

$data = array( 'id' => $this->post('id'),
               'name'  => $this->post('name'),
               'location' => $this->post('location'),
               'tgl' => $this->post('tgl'),
               'addrs' => $this->post('addrs'));

正如您在编辑功能中所做的那样

$data = array( 'id' => $this->post('id'),
               'name'  => $this->post('name'),
               'location' => $this->post('location'),
               'tgl' => $this->post('tgl'),
               'addrs' => $this->post('addrs'));

正如您在编辑功能中所做的那样