簡體   English   中英

Restler中的REST服務在部署到測試服務器后找不到任何路由

[英]REST service in Restler cannot find any route after deployed to test server

Restler 3.0.0rc6。

我在本地開發環境中的Restler中設置了一個簡單的REST服務。 當我移至測試服務器后,Restler無法找到任何路由。

我通過遠程主機將項目與git同步。 我剛剛將最新的本地更改拉到了我的測試服務器,因此文件夾設置應該沒問題。

錯誤出現在方法find人試圖找到與請求的URL匹配的api方法的Routes.php行362中。 該文件中的指令:

$p = Util::nestedValue(static::$routes, "v$version");

返回$p = NULL 調用中的參數值為:

static::$routes is an empty array - array(). 
$version is int(1)

此代碼之后,如果$p = NULL則條件觸發異常。

我嘗試了最小的Hello world示例,並總是遇到相同的問題。

由於該應用程序在我的本地服務器上運行良好,因此我可以想到測試服務器中的某些配置使一切混亂,但無法跟蹤它的含義。 由於我不知道從哪里開始,所以只提供一些信息以防萬一。

我包括我的文件夾配置:

html/api/ -> index.php and custom class files
html/api/data-base -> database acces files 
html/api/vendor -> Restler

我的index.php文件

<?php
require_once 'vendor/restler.php';
require_once('data-base/data-base-pdo.php');
use Luracast\Restler\Restler;
$r = new Restler();
$r->addAPIClass('Individuals');
$r->addAPIClass('Injuries');
$r->addAPIClass('Measurements');
$r->addAPIClass('Sessions');
$r->addAPIClass('Reports');
$r->handle();

我的課程文件之一:

<?php
use Luracast\Restler\RestException;
class Individuals
{
    public $db;
    public function __construct() {
        $this->db = DataBase::getInstance();
    }

    public function index() {
        return $this->db->individualsSelect();
    }

    public function get($id) {
        try {
            return $this->db->individualsSelectOne($id);
        } catch(mysqli_exception $e) {
            throw new RestException(500, $e->getMessage(), array(), $e);
        } catch(InvalidArgumentException $e) {
            throw new RestException(400, $e->getMessage(), array(), $e);
        }
    }

    public function put($id, $request_data) {
        try {
            return $this->db->individualsUpdate($id, $request_data);
        } catch(mysqli_exception $e) {
            throw new RestException(500, $e->getMessage(), array(), $e);
        } catch(InvalidArgumentException $e) {
            throw new RestException(400, $e->getMessage(), array(), $e);
        }       
    }

    /**
     * @url GET {individuals_id}/injuries
     */
    public function injuries($individuals_id) {
        try {
            return $this->db->injuriesSelectByIndividual($individuals_id);
        } catch(mysqli_exception $e) {
            throw new RestException(500, $e->getMessage(), array(), $e);
        } catch(InvalidArgumentException $e) {
            throw new RestException(400, $e->getMessage(), array(), $e);
        }
    }

    /**
     * @url GET {individuals_id}/measurements
     */
    public function measurements($individuals_id) {
        try {
            return $this->db->measurementsSelectByIndividual($individuals_id);
        } catch(mysqli_exception $e) {
            throw new RestException(500, $e->getMessage(), array(), $e);
        } catch(InvalidArgumentException $e) {
            throw new RestException(400, $e->getMessage(), array(), $e);
        }
    }

    /**
     * @url GET {individuals_id}/sessions
     */
    public function sessions($individuals_id) {
        try {
            return $this->db->sessionsSelectByIndividual($individuals_id);
        } catch(mysqli_exception $e) {
            throw new RestException(500, $e->getMessage(), array(), $e);
        } catch(InvalidArgumentException $e) {
            throw new RestException(400, $e->getMessage(), array(), $e);
        }
    }
}

問題出在文件名和類名的大小寫上。 我所有的筆錄都以大寫字母開頭,例如“ Individuals ,但是文件都是小寫字母,例如“ individuals.php .php”。 我的開發環境不區分大小寫,因此Restler可以找到我的文件,但是一旦我將其部署到測試服務器中,一切都將被破壞。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM