Jump to content

<p>How to use and access the API</p>


Nabeel
  • API Documentation and Reference

    To view the available API functions, click the second link above. From the left, select "Class Hierarchy", then select "CodonData". Under that, all of the API data classes available are listed there. Beginning with ACARSData.

    ccs-2-12668039094268_thumb.png

    Click on "ACARSData", and the frame to the right will load. Scroll down to "Static Public Member Functions", which will list the available functions in that class.

    ccs-2-12668041065843_thumb.png

    More details are below, starting with "Basic Format".

    API Access

    You can access the API through nearly any place, including template, modules and your skin. You can also access it from any page that's not included in the system (ie, a standalone PHP page).

    To include it in a standalone page, simply include the core/codon.config.php file at the top of your script:

    include '/path/to/core/codon.config.php';
    
    // You can then access the API normally from here

    Basic Format

    The API are all static classes, so you do not have to instantiate any variables or classes in order to use it. This has a few advantages - the code is cleaner, and less memory is used. The format is:

    $value = [ClassName]::[Function]([options]) 

    Normally, the ClassName will have the word “Data” in it, to indicate it's for data. These are purely database calls, and do not have any HTML. 99% of the time, they will return an array of objects which contain the data you need.

    Working with API functions

    This is easiest illustrated through an example. As listed above, "Document and Reference", select PilotData, and for the function, select “getAllPilots”. We can see you pass in an optional letter for the last name, but we will ignore that. So our function will be:

    $pilots = PilotData::getAllPilots();
    

    It returns an "array of objects", which we will loop through like this:

    $pilots = PilotData::getAllPilots();
    foreach($pilots as $pilot)
    {
    print_r($pilot);
    }
    

    The print_r() will output the contents of $pilot:

    stdClass Object
    (
    [pilotid] => 1
    [firstname] => Nabeel
    [lastname] => Shahzad
    [email] => nabeel@nsslive.net
    [code] => VMS
    [location] => US
    [hub] => KJFK
    [password] => e78f99f630b75e867acae85ef9837391
    [salt] => b58686bd783f38d77ab493a8aa2053c4
    [bgimage] => background.png
    [lastlogin] => 2010-01-04
    [totalflights] => 16
    [totalhours] => 60.35
    [totalpay] => 2621
    [transferhours] => 100
    [rank] => Captain
    [confirmed] => 1
    [retired] => 0
    [joindate] => 2009-08-23 16:14:44
    [lastpirep] => 2010-01-03 18:39:38
    )
    

    And it will output one of those for each entry found. We can work with this some more - on top we see it says “stdClass Object”. And then it lists all the properties in brackets [], and then the value after the ⇒. To then get the variable we can do:

    $pilots = PilotData::getAllPilots();
    foreach($pilots as $pilot)
    {
    echo "{$pilot->firstname} {$pilot->lastname}";
    }

    Which will then output:

    Nabeel Shahzad 

    Working with any API functions is similar to this for retrieving data. Nearly anything you would need to do is covered by the API.

How to use and access the API


User Feedback

Recommended Comments

There are no comments to display.



Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Add a comment...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...