File: plugins/custom/example.hooks.php

Recommend this page to a friend!
  Classes of Marco Cesarato  >  PHP API Database  >  plugins/custom/example.hooks.php  >  Download  
File: plugins/custom/example.hooks.php
Role: Example script
Content type: text/plain
Description: Example script
Class: PHP API Database
Provide access to database records via REST API
Author: By
Last change: Reformatted code (php-cs-fixer)

Added code standard,
Added hooks git for code standard,
Fixed parse where on null elements
Date: 9 months ago
Size: 1,112 bytes
 

Contents

Class file image Download
<?php
/**
 * Hooks - Custom API Call - Example.
 *
 * @author Marco Cesarato <cesarato.developer@gmail.com>
 */
use marcocesarato\DatabaseAPI\API;
use
marcocesarato\DatabaseAPI\Auth;
use
marcocesarato\DatabaseAPI\Hooks;

$hooks = Hooks::getInstance();

/**
 * Custom API Call.
 *
 * @return mixed or die (with mixed return just skip to next action until 404 error)
 */
function action_custom_api_call_example()
{
   
$user = Auth::getUser(); // User row
   
$api = API::getInstance(); // PDO Object
   
$db = API::getConnection('dataset'); // $db MUST NOT BE EMPTY or WILL CAUSE A LOOP

    // Example url: example.com/TOKEN/part_1/part_2/part_3.format
   
$part_1 = $api->query['part_1'];
   
$part_2 = $api->query['part_2'];
   
$part_3 = $api->query['part_3'];

   
// example.com/TOKEN/example/something.json
    /*if($part_1 == 'example') {
        $example = new StdClass();
        $example->id = '1';
        $example->desc = "Example custom call";
        $api->render(array($example, $example, $example));
    }*/
}

$hooks->add_action('custom_api_call', 'action_custom_api_call_example');


For more information send a message to info at phpclasses dot org.