php Restler Rutas

I am using Restler 2.0 and I'm trying to add a new route based on the CRUD example

$o['GET']['author/:name/:email']=array (
  'class_name' => 'Author',
  'method_name' => 'getLogin',
  'arguments' => 
  array (
    'name'  => 0,
    'email' => 1,
  'defaults' => 
  array (
    0 => NULL,
    1 => NULL,
  'metadata' => 
  array (
  'method_flag' => 0,

when I make the url call in the browser http://[host]/author/[name to pull]/[email to pull]

Obtuve el siguiente error:

  "error": {
    "code": 404,
    "message": "Not Found"

my author code has been updated with the following method

function getLogin($name=NULL,$email=NULL) {
    print "in author, getting login";
    return $this->dp->getLogin($name,$email);

Estoy perplejo.

preguntado el 08 de noviembre de 11 a las 13:11

1 Respuestas

Luracast Restler Auto Routing

En primer lugar, routes.php is auto generated when you run Restler in production mode

$r = new Restler(TRUE);

which will be overwritten when we call


or run it in debug mode, so it should not be hand coded.

Restler 2.0 esta usando mapeo automático which is better explained in the updated CRUD Example.

Corrected version of your method should be

function get($name=NULL,$email=NULL) {
    print "in author, getting login";
    return $this->dp->getLogin($name,$email);

which will map to

GET /author/:email/:password

where as your method is currently mapping to

GET /author/login/:email/:password

Luracast Restler Custom Routing

Also note that you can use PHPDoc comment to create custom mappings and you can add more than one. For example

* @url GET /custom/mapping/:name/:email
* @url GET /another/:name/:email
function get($name=NULL,$email=NULL) {
    print "in author, getting login";
    return $this->dp->getLogin($name,$email);

this will create the following routes, and disable auto routing for that method.

GET /author/custom/mapping/:email/:password
GET /author/another/:email/:password

respondido 11 nov., 11:21

I understand now. That's actually what I wanted. the CRUD example downloaded had a routes.php provided with the example (example 06). I assume this was to provide specific mapping. Thanks! - Cavelle Benjamin

@CavelleBenjamin You are right, presence of routes.php with out explanation creates confusion, I will remove it in the next update. - Arul Kumaran

Please don't remove unless there will be a simpler way of adding specific routes. app specific routes.php file is powerful and great. Thanks! - Cavelle Benjamin

@CavelleBenjamin I'm not removing the feature, just the file which is not used in development mode. Easy way to add custom routes is by adding a PHPDoc comment at the top of your method like @url GET /my/custom/url I'm updating my answer above to include an example - Arul Kumaran

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.