我在编码器中得到“{”status“:false,”error“:”false“}”为什么?

时间:2017-06-24 13:07:22

标签: php api

我的代码中有错误,我在php框架中编写代码`codeignater,我想扩展REST_Controller但我不能,我的代码不能正常工作,请帮帮我,这是我的错误和我的代码, {“status”:false,“error”:false}

controller / Auth.php

<?php

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

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

//require('libraries\Format.php');

class Auth  extends REST_Controller
{

    function __construct()
    {
        parent::__construct();
        $this->load->model('api_model');
//        $this->load->library('rest_controller_lang');

    }

    function data_post()
    {
        $data = array(
            'name' => $_POST['name'],
            'surename' => $_POST['surename'],
            'email' => $_POST['email'],
            'password' => $_POST['password'],

        );
        $this->api_model->insert($data);
        $this->response("my first api");
        var_dump($data);
  }
}

?>

模型/ Api_model.php

<?php

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

class Api_model extends CI_Model
{
    public function __construct()
    {
        parent::__construct();
    }


    public function insert($data){
        if($this->db->insert('peoples', $data)){
            return FALSE;
        }
        return TRUE;
    }
}

?>

配置/ autoload.php

$autoload['libraries'] = array('database','REST_Controller');

1 个答案:

答案 0 :(得分:0)

application / libraries / Format.php application / libraries / REST_Controller.php 文件拖放到应用程序的目录中。复制 rest.php 进入你的** application / config **目录。

对于代码,请尝试直接引用控制器。

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

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

 class Auth extends \Restserver\Libraries\REST_Controller
 {......}

我在REST_CONTROLLER

中添加了namespace Restserver\Libraries;
<?php
 namespace Restserver\Libraries;

  use Exception;
   use stdClass;

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

   abstract class REST_Controller extends \CI_Controller
    {......}

对于响应,请尝试随身携带HTTP代码

$this->response("my first api", 200);