普通网友 2018-10-10 22:27
浏览 58

Autoload Rest Server API codeigniter

I have the same exact issue with: Codeigniter 3 autoload controller

that I want to autoload the Libary automatically so I won't declare this:

use Restserver\Libraries\REST_Controller;
defined('BASEPATH') OR exit('No direct script access allowed');

// This can be removed if you use __autoload() in config.php OR use Modular Extensions
/** @noinspection PhpIncludeInspection */
//To Solve File REST_Controller not found
require APPPATH . 'libraries/REST_Controller.php';
require APPPATH . 'libraries/Format.php';

/**
 * This is an example of a few basic user interaction methods you could use
 * all done with a hardcoded array
 *
 * @package         CodeIgniter
 * @subpackage      Rest Server
 * @category        Controller
 * @author          Phil Sturgeon, Chris Kacerguis
 * @license         MIT
 * @link            https://github.com/chriskacerguis/codeigniter-restserver
 */

in every Controller. I tried extending it core/MY_Controller as suggested in the answer in the link I provided above, here's my core/MY_Controller.php looks like:

<?php
use Restserver\Libraries\REST_Controller;
require APPPATH . 'libraries/REST_Controller.php';
require APPPATH . 'libraries/Format.php';

class MY_Controller extends CI_Controller
{

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

    }

}

?>

and upon running the controller/Example.php, methods from the rest api library is unknown. and having this error:

Message: Call to undefined method Phone::get()

Filename: C:\xampp\htdocs\mainline\application\controllers\api\Phone.php

Line Number: 16

Example.php

class Phone extends MY_Controller
{
    public function __construct()
    {
        parent::__construct();
    }

    public function index_get()
    {

        $message = [
            'id' => 100, // Automatically generated by the model
            'name' => $this->get('name'),
            'email' => $this->get('email'),
            'message' => 'Invalid request'
        ];
        $this->set_response($message, REST_Controller::HTTP_CREATED); // CREATED (201) being the HTTP response code
    }
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥30 这是哪个作者做的宝宝起名网站
    • ¥60 版本过低apk如何修改可以兼容新的安卓系统
    • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
    • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
    • ¥50 有数据,怎么用matlab求全要素生产率
    • ¥15 TI的insta-spin例程
    • ¥15 完成下列问题完成下列问题
    • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
    • ¥15 YoloV5 第三方库的版本对照问题
    • ¥15 请完成下列相关问题!