dounieqi6959 2015-03-24 23:56
浏览 89

Restler中的REST服务在部署到测试服务器后找不到任何路由

Restler 3.0.0rc6.

I have setup a simple REST service in Restler in my local development environment. When I have moved to test server, Restler cannot find ANY route.

I have the projects in sync with git via a remote host. I have just pulled the latest local changes to my test server, so the folder setup should be fine.

The error comes in Routes.php line 362 in the method find who tries to locate the api method matching the requested url. The instruction in this file:

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

returns $p = NULL. The param values in the call are:

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

After this code a conditional triggers an exception if $p = NULL.

I have tried the mininum Hello world example and get always the same problem.

Since the app was working fine on my local server I can think of some configuration in my test server that is messing everything, but cannot track what is it. Since I don't know where to start I just include some info in case it can be useful.

I include my folder configuration:

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

My index.php file

<?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();

One of my class files:

<?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);
        }
    }
}
  • 写回答

1条回答 默认 最新

  • doulingna9420 2015-03-25 21:23
    关注

    The problem was with the Case in file names and class names. All my clases start with Uppercase like Individuals, but the files are all lowercase like individuals.php. My develpment environment is not case sensitive so restler could find the files for my clases but as soon as I deployed in my test server everything was broken.

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题