3

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]

I get the following 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);
}

I am stumped.

472084
  • 17,666
  • 10
  • 63
  • 81

1 Answers1

0

Luracast Restler Auto Routing

Firstly, routes.php is auto generated when you run Restler in production mode

$r = new Restler(TRUE);

which will be overwritten when we call

$r->refreshCache();

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

Restler 2.0 is using auto mapping 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
Arul Kumaran
  • 983
  • 7
  • 23
  • 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 Nov 09 '11 at 00:48
  • @CavelleBenjamin You are right, presence of routes.php with out explanation creates confusion, I will remove it in the next update. – Arul Kumaran Nov 09 '11 at 13:19
  • 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 Nov 11 '11 at 13:46
  • @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 Nov 11 '11 at 17:05