Core Boxx – Core Library Reference

MODULES

function load($module)

Loads lib/LIB-$module.php, and extends it to $_CORE->$module = new $module();

  • $module – String, module to load.
$_CORE->load("Users");
function loaded($module)

Checks if the specified $module is loaded.

  • $module – String, module to check.
if ($_CORE->loaded("Users")) { ... }

 

FUNCTION MAPPING

function autoCall($module, $function, $mode)

Automatically map POST or GET variables to the specified module function, and run it.

  • $module – String, module to load.
  • $function – String, function to call.
  • $mode – String, POST or GET. Defaults to POST.
$users = $_CORE->autoCall("Users", "getAll");
function autoAPI($module, $function, $mode)

Automatically map POST or GET variables to the specified module function, and respond after running it.

  • $module – String, module to load.
  • $function – String, function to call.
  • $mode – String, POST or GET. Defaults to POST.
$_CORE->autoAPI("Users", "save");
function autoGETAPI($module, $function, $mode)

Automatically map POST or GET variables to the specified module (get entries) function, and respond after running it.

  • $module – String, module to load.
  • $function – String, function to call.
  • $mode – String, POST or GET. Defaults to POST.
$_CORE->autoAPI("Users", "save");

 

 

SYSTEM

function respond($status, $msg, $data, $more, $http, $exit)

Formats and outputs a standard JSON encoded string.

  • $status – Boolean, 1, 0, or invent your own set of status code.
  • $msg – String, system message.
  • $data – Data if any.
  • $more – Additional data, if any.
  • $http – Optional, HTTP response code.
  • $exit – Optional, stop processing after JSON string output. Defaults to true.
$_CORE->respond(0, "An error has occurred!", null, null, 500);
function ouch($ex)

Nothing to see here. This one is used to handle errors globally.

function random($length)

Creates an alphanumeric string.

  • $length – Integer, number of bytes. Defaults to 8.
$password = $_CORE->random(10);

 

OTHER CONVENIENCE

function paginator($entries, $now)

Calculates pagination.

  • $entries – Integer, the total number of entries.
  • $now – Integer, the current page number.
$entries = 1234; // DO YOUR OWN SELECT COUNT(*) FROM `TABLE`
$now = 4; // CURRENT PAGE
$page = $_CORE->paginator($entries, $now);
/* $page = [
  "entries" => TOTAL NUMBER OF ENTRIES
  "total" => TOTAL NUMBER OF PAGES
  "now" => CURRENT PAGE
  "x" => USE THIS TO LIMIT X,Y YOUR SQL QUERY
  "y" => USE THIS TO LIMIT X,Y YOUR SQL QUERY
] */
function redirect ($page, $url)

HTTP redirect.

  • $page – Page or path.
  • $url – Defaults to HOST_BASE.
if (!isset($_SESSION["user"])) {
  $_CORE->redirect("login/");
}

Leave a Comment

Your email address will not be published.