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);
}
}
}