One approach is handling both cases in same function with a conditional block as shown below
function get($id, $action=null){
if(is_null($action)){
//handle it as just $id case
}else{
//handle it as $id and $action case
}
}
if you are running restler 3 and above you have to disable smart routing
/**
* @smart-auto-routing false
*/
function get($id, $action=null){
if(is_null($action)){
//handle it as just $id case
}else{
//handle it as $id and $action case
}
}
Another approach is to have multiple functions since index also maps to root, you have few options, you can name your functions as get, index, getIndex
function get($id, $action){
//returns data based on action and id
}
function index($id){
//returns profile based on id
}
If you are using Restler 2 or turning smart routing
off, order of the functions is important to fight ambiguity
If you are running out of options for function names you can use @url mapping as @fiskfisk suggested but the route should only include from method level as the class route is always prepended unless you turn it off using $r->addAPIClass('MyClass','');
function get($id){
//returns data based on action and id
}
/**
* @url GET :id/duels
*/
function duels($id)
{
}
HTH