首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Codeigniter chriskacerguis-RESTAPI未知存取方法

Codeigniter chriskacerguis-RESTAPI未知存取方法
EN

Stack Overflow用户
提问于 2016-09-13 07:17:52
回答 1查看 296关注 0票数 0

这是我的文件夹

代码语言:javascript
复制
Controller
  L>API
    L>ID
      L>Example.php
  L>Example.php

我在API/example.php的example.php和API/ID/example.php都是相同的。

代码语言:javascript
复制
<?php

defined('BASEPATH') OR exit('No direct script access allowed');
require APPPATH . '/core/REST_Controller.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
 */

class Example extends REST_Controller {
    public function index_get()
    {
        // index from a data store e.g. database
        $index = [
            ['id' => 1, 'name' => 'John', 'email' => 'john@example.com', 'fact' => 'Loves coding'],
            ['id' => 2, 'name' => 'Jim', 'email' => 'jim@example.com', 'fact' => 'Developed on CodeIgniter'],
            ['id' => 3, 'name' => 'Jane', 'email' => 'jane@example.com', 'fact' => 'Lives in the USA', ['hobbies' => ['guitar', 'cycling']]],
        ];

        $id = $this->get('id');
        $this->response($index, REST_Controller::HTTP_OK);
    }

    public function users_get(){
       echo"test";die();
    }
}

首先,我像下面这样调整我的config/whoes.php

代码语言:javascript
复制
$route['API'] = "API";
$route['API/(.+)'] = "API/$1";

当我访问base_url/API/Example/id/1时,它响应名为John的$index1。

然后我把routes.php改为

代码语言:javascript
复制
$route["API/example"]="API/ID/example";
$route["API/example/(.+)"]="API/ID/example/(.+)";

然后我访问了base_url/API/Example/id/1,它将基于routes.php访问API/ID/base,但它的响应

代码语言:javascript
复制
{
"status": false
"message": "Unknown method"
}

但是,如果我访问base_url/API/示例?id=1,则它使用$index1响应。

如何使用base_url/ api /样例/id/1从API/id/exprese.php调用API,它将返回$index1?非状态:假未知方法

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-09-16 03:24:40

我知道解决办法,因为我的路线是错的。

代码语言:javascript
复制
$route['API/search_location/(.+)']="API/ID/example/index/$1";
$route['API/search_location']="API/ID/example";
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39464238

复制
相关文章

相似问题

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