Search code examples
restler

Restler - Call method from another API class


In my Restler index.php let's say I've done this:

$r->addAPIClass('Person');
$r->addAPIClass('Team');

And now I'm inside one of the methods defined in Person, and I have a need to call one of the methods defined in Team. What's the right way to get a handle to the Team API so that I can call one of its methods?


Solution

  • There is nothing special, doing it with Restler.

    If it is a static method directly call Team::method(parameter)

    Otherwise create an instance either

    • at constructor if you need it in many methods and store it in a private variable
    • at the method level

    If you are using a database model, it may already provide you with an instance of team as a relationship