Cart Boxx – Base Library Reference

THE CLASS ITSELF

class CartBoxx

File: cart-boxx/index.php
Description: The Cart Boxx base engine, a $_CB object of class CartBoxx will be initiated in index.php by default.

 

THE BASICS

function init

Description: Loads all the configuration and connect to database.

Parameters
None
Return
None, but halts the system on errors.
function verbose

Description: Creates a standard JSON system message. Used in every function and API call.

Parameters
[INT] $status – 0 for error, 1 for success
[STRING] $module – Related module
[STRING] $msg – Message to display
[ARRAY/STRING] $more – More information, for example, array of user data.
[BOOL] $halt – Halt the process and throw out system message? Default false.
Return

None, but will set $_CB->sysmsg used in API calls and processes.

  • cb-status – 1 for success, 0 for fail
  • cb-mod – The related module that caused an error or responded successfully
  • cb-msg – The system/error message
  • cb-more – Container for extra data, for example, user data on an API call to fetch users
function extended

Description: Checks if Cart Boxx already has extended the specified module.

Parameters
[STRING] $branch – Target module.
Return
[BOOL] True for yes, false for no.
function extend

Description: Extend specified module to Cart Boxx. Will look for the physical file in cart-boxx/core/lib/LIB-$branch.php, extend it to $_CB->$branch = new $branch().

Parameters
[STRING] $branch – Target branch to extend.
Return
[BOOL] True on success, false on failure

 

THE BASICS

function getCFG

Description: Get/set system config from database

Parameters
[INT/ARRAY] $group – Config group ID. Provide a single integer, or array of integers, e.g. [1,2,3,4]
[BOOL] $set – If true, will directly define(CONFIG_KEY,CONFIG_VALUE). If false, this function will return the config values in an array.
Return
[BOOL] If $set is true, this will return true on success, false on failure.
[ARRAY] If $set is false, this will return an array of config data.
function getCFGKey

Description: Get config by key

Parameters
[STRING/ARRAY] $key – Config key, provide a single config key, or array of config keys. E.g. [“KEY_ONE”, “KEY_TWO”]
Return
[ARRAY] Config data
function setCFG

Description: Update the configuration in the database

Parameters
[ARRAY] $cfg – An array of config data. E.g. [“KEY_ONE”=>”VALUE”, “KEY_TWO”=>”VALUE”]
Return
[BOOL] True on success, false on failure.

 

CRYPTO

function crypt

Description: Encrypts the given plain text – Use this for passwords and sensitive data.

Parameters
[STRING] $plain – Plain text to encrypt
[STRING] $cipher – Encryption method to use. Default AES-128-ECB.
[STRING] $key – Secret Key. Defaults to SECRET_KEY set in config.php
Return
[STRING] Encrypted string.
function decrypt

Description: Decrypts the given cipher text.

Parameters
[STRING] $plain – Cipher text to decrypt
[STRING] $cipher – Encryption method to use. Default AES-128-ECB.
[STRING] $key – Secret Key. Defaults to SECRET_KEY set in config.php
Return
[STRING] Plain text.

 

EVERYTHING ELSE

function mail

Description: Sends an email

Parameters
[STRING] $to – Target email to send to
[STRING] $subject – Subject of email
[STRING] $msg – The email message
[BOOL] $debug – If true, will save to a file cart-boxx/mail.txt. Default false.
Return
[BOOL] True on success, false on failure
function random

Description: Creates a random string.

Parameters
[INT] $length – Number of characters to generate.
Return
[STRING] Random string
function pages

Description: For pagination use – Calculates the total number of pages.

Parameters
[INT] The total number of entries
[INT] PER_PAGE must be defined
Return
[INT] Number of pages
Example Usage
$pages = $_CB->pages($_CB->Users->countUsers());
function slimit

Description: Used for pagination, automatically generates a trailing “LIMIT X,Y” SQL.

Parameters
[INT] $pg – Current page number
[INT] PER_PAGE must be defined
Return
[STRING] LIMIT X,Y
Example Usage
// Let’s say we are on page 2 of manage users now
$page = 2;
$sql = “SELECT * FROM `users`”;
$sql .= $_CB->slimit(2);

Leave a Comment

Your email address will not be published. Required fields are marked *