Reputation: 1
We're exploring the Restler framework. What we need is a custom route like:
[host]/:sessionid/{class}/{method}?param1=x¶m2=y
For example, the Settings
method in the Game
class:
<?php
class Game {
function settings($session, $sound=TRUE, $music=TRUE){
//
}
}
?>
should map to http://hostname/12435635/game/settings?sound=x&music=y
We've managed to achieve it by hacking the routes.php
file a bit, but as the file is auto-generated the idea is not very good. So, is it possible to create such routes without hacking the Restler's source or modifying the routes.php
file?
Upvotes: 0
Views: 691
Reputation: 993
First step is to remove class name from the URI. It can be achieved by modifying the addAPIClass
statement
$r->addAPIClass('Game', '');
this changes the auto generated uri structure as follows
http://hostname/settings/12435635/?sound=x&music=y
Next step is to specify a route manually by adding a PHPDoc comment to the api method as shown below
<?php
class Game {
/**
* @url GET /:session/game/settings
*/
function settings($session, $sound=TRUE, $music=TRUE){
//
}
}
This will map to
http://hostname/12435635/game/settings?sound=x&music=y
This route will be added to routes.php
every time it is generated in production mode :)
You may add more @url comments to create multiple routes to the same method
Upvotes: 1