Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Luracast Restler PHP how to specify a default class method for the root path

Tags:

php

frameworks

I working with Luracast Restler API frame work and cannot figure out how to specify a default behavior for the root directory. For example:

webroot/user - will invoke the class User method get() by default

webroot/ - return a 404

Is there a catch all class/method for the base path?

like image 596
punkael Avatar asked Mar 22 '26 11:03

punkael


1 Answers

Creating default class and default action to map it as the root

on your index.php (gateway)

require_once '../../restler/restler.php';
require_once 'say.php';
$r = new Restler();
//blank string as the second param removes class_name from the URL
$r->addAPIClass('Say','');
$r->handle();

This makes Say as the default class, mapped to the root Next on your API class (Say) define an index method, it can also be a get method

class Say {
    function index($to='world') {
        return "Hello $to!";
    }
}

then calling

GET index.php

will return Hello World!

like image 108
Arul Kumaran Avatar answered Mar 23 '26 23:03

Arul Kumaran



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!