NAV Navbar
php javascript htaccess

Introduction

Welcome to PHP Shark - An Intensive PHP MVC framework for Advanced Developers. It has basic functionality of putting up complex portals in minutes. However it is as much RAW as PHP is an Being a Deliverable Framework. It is Not to be compare with Competent - CAKEPHP, CODEIGNITER or LARAVEL. The reason being - it was built to meet its own Market challenges - and Hence, it is Portal Framework.

PHP Shark - As the name suggest is written in PHP Language. It is specifically focused upon the Database, HTTP Requests and the security being the central part of it. It has a powerful Query Library built upon PDO Architecture.

Deploy PHP Shark

PHP Shark has some pre-requisites and configurations.

  1. Make sure your database is properly setup.
  2. Update your Configuration file in the project folder with proper credentials.
  3. You need to set up a router.php placed inside the project folder for external links.
  4. Be sure to place and error page for your typical - 404 Page not found to avoid ugly Messages.

Basic Configurations

Tag Description
PROJECT Description of you project.
BASE The base link of your project on server.
ENVIRONMENT It takes up the values - [development, quality, production]
DATASOURCE Specifies the name of your Database. (Example - MySql).
PORT Specifies the port of your Database (Default Example - 3306).
DATABASE Specifies the database of your Database.
LOGIN Specifies the login user of your Database.
PASSWORD Specifies the password of your Database.
SECURITY_SALT Specifies the security hashing Key for your password. This will be used for your password hashing when you create the login system of your application.

Project Setup

This application was developed using Xampp Apache Web Server.

  1. Upload the copy of your PHP Spark into the web server.
  2. Setup a database connection with a username / password.
  3. Configure the file "config.xml" with Basic Configuration.

And Boom!!! Jump over the SRC folder to create your first Hello World Page.

Hello World!

Once your Project is setup. Lets put the first ever app created APP - Hello World!.

We will start by creating the following three things.

  1. Adding router
  2. Creating a controller
  3. Creating a Model
  4. Creating a View

We will access

GET http://example.com/hello

Adding a router

Router file is a pointer file. It points the direction of the links to the files available inside the source folder. if the pointed file does not exist, or is not pointed, the router is automatically directed to the error.

For this page will create a namespace: public and an Index Class inside it. This is how the hierarchy will look like.

We have already created the default ones.

Router::route("/",["path" => "public"]);

Router::route("404",["path" => "public".DS."error"]);

<?php
Router::route("hello",["path" => "public".DS."hello"]);

Creating a controller

Controller

  1. namespace to be accessed from admin area.
  2. class that extends \AppController.
  3. class constructor with its parent construct - A Must.
  4. A default index method.
<?php
  namespace hello{
      class Index extends \AppController{
         public function __construct(){
            parent ::__construct();
         }

         public function index(){
           $this->view->render("index");
         }
      }
   }

Creating a Model

required:

  1. namespace to be accessed from admin area.
  2. class renamed with "_Model" that extends \AppModel.
  3. class constructor with its parent construct - A Must.
<?php
  namespace hello{
      class Index_Model extends \AppModel{
         public function __construct(){
            parent ::__construct();
         }
      }
   }

Creating a View

A View file is a front-end file, the view support client side frameworks and browser languages such as HTML5/CSS and Javascript.

required:

  1. First convention of a view folder is that it is places inside the folder of its controller.
  2. Second convention is that it has to be named with '_view'. example index_view.php
<!doctype html>
<html>
  <head>
      <title>Hello World</title>
  </head>
  <body>
      <p>Hello World!!</p>
  </body>
</html>

The Scenario: Country Page

Project

One of my clients had a requirement of setting up pages in the following formats. they wanted 5 Sections

For the above links the src (source) structure folder is places as below.

The folder and root folder hierarchy specifically contribute to the links as

Root -> Namespace ->Link Controller.

<?php
Router::route("member",["path" => "customers".DS."members"]);
Router::route("dealer",["path" => "customers".DS."dealers"]);
Router::route("admin",["path" => "admin".DS."admin"]);
Router::route("agent",["path" => "admin".DS."agents"]);
//Public
Router::route("404",["path" => "public".DS."error"]);
Router::route("denied",["path" => "public".DS."denied"]);
Router::route("/",["path" => "public"]);

I Will put a sample country page as an Example

PHPShark: MVC Structure

PHPShark follows the same MVC structure as all other frameworks do. However, here it is placed inside its namespace folder and then all its - Model-View-Controller resides in the same place.

  1. GET http://example.com/admin/country
  2. POST http://example.com/admin/country/add
  3. PUT http://example.com/admin/country/edit/1

Creating the database table

Creating the country table.

<?php

if(!\orm\Query::is_table('country')){
    \orm\Table::create()
      ->table('country')
      ->field('countries_id')->type('i(11)')->constraint('UNSIGNED NOT NULL')->auto_increment()
      ->field('country_name')->type('varchar(50)')->constraint('NOT NULL')
      ->field('country_code')->type('varchar(50)')->constraint('NOT NULL')
      ->primary('type_id')
      ->execute();
}
?>

Altering the database table

Adding tow fields created and modified to the country table.

<?php

  if (!orm\Query::is_field('country', 'modified')) {
      $this->alter([
        'table' => 'country',
        'field' => 'modified',
        'operation' => 'add',
        'type' => 'datetime',
        'null' => false,
      ]);
   }

  if (!orm\Query::is_field('country', 'created')) {
    $this->alter([
      'table' => 'country',
      'field' => 'created',
      'operation' => 'add',
      'type' => 'datetime',
      'null' => false,
    ]);
  }

CRUD operations

Insert Query

INSERT INTO countries (country_name, country_code) VALUES ("India","IN")

  <?php
  // Insert Query
  $ins = $this->db->insert("countries")
                  ->values(["country_name", "country_code"])
                  ->x();

  $this->db->parameter("country_name",'India');
  $this->db->parameter("country_code",'IN');
  $ins   = $this->db->fetch();

$ins now holds the last inserted id into the table

Select Query

SELECT country_id, country_name, country_code FROM countries WHERE countries_id = 1

  <?php
  // Select Query
  $this->db->select(["countries_id", "country_name", "country_code"])
           ->from("countries")
           ->where("countries_id = id")
           ->x();

  $this->db->parameter("id",'1');
  $sel   = $this->db->fetch();
  $count = $this->db->dbCount();

  //Expose the result as JSON Object
  echo $this->json->encode($sel);

UPDATE Query

UPDATE TABLE countries SET country_name = "Bharat" WHERE countries_id = 1

  <?php
  // Update Query
  $upd = $this->db->update("countries")
            ->set(["country_name"])
            ->where("countries_id = id")
            ->x();

  $this->db->parameter("country_name",'Bharat']);
  $this->db->parameter("id",'1');
  $upd = $this->db->fetch();

$udp will hold the value of true and false now.

DELETE Query

DELETE users WHERE user_id = 1

  <?php
  //Delete Query
  $this->db->delete("users")->where("user_id = id")->x();
  $this->db->parameter("id",'1');
  $this->db->fetch();

The Controller

  <?php
  namespace admin{
      class Country extends \AppController{
          public function __construct(){
              parent::__construct();
          }

          public function index(){
              $this->view->title("Admin - Country Configuration");
              $this->view->render("index");
          }

          public function add(){
              $this->view->title("Admin - Country Configuration | Add");
              $this->view->render("add");
          }

          public function edit(int $id){
              if($id !== null){
                  $this->view->title("Admin - Country Configuration | Edit");
                  $this->view->set("id", $id);
                  $this->view->render("edit");
              }else{
                  request_page("error");
              }
          }

          public function xhrGetList(){
             if(action_check("post")){
                  $list = $this->model->listCountry();
              }
          }

          public function xhrGetIndexByID($id){
              if(action_check("get")){
                  $this->model->getCountryById($id);
              }
          }

          public function xhrAdd(){
            if(action_check("post")){
                 $this->model->addCountry($_POST);
             }
          }

          public function xhrUpdate($id){
             if(action_check("post")){
                  $this->model->updateCountry($_POST,$id);
             }
          }

          public function xhrDelete($id){
              if(action_check("post")){
                  $this->model->deleteCountry($id);
              }
          }
      }
  }

The Model

  <?php

  namespace admin{
      class Country_Model extends \AppModel{
          public function __construct(){
              parent::__construct();
          }

          public function listCountry(){
              $this->db->select(["countries_id", "country_name", "country_code"])
                       ->from("countries")
                       ->x();

              $sel   = $this->db->fetch();
              $count = $this->db->dbCount();

              echo $this->json->encode($sel);
          }

          public function getCountryById(int $id){
              $this->db->select(["countries_id", "country_name", "country_code"])
                       ->from("countries")
                       ->where("countries_id = id")
                       ->x();

              $this->db->parameter("id",$id);

              $sel   = $this->db->fetch();
              $count = $this->db->dbCount();
              echo $this->json->encode($sel);
          }

          public function addCountry(array $data){
              $ins = $this->db->insert("countries")
                       ->values(["country_name", "country_code"])
                       ->x();

              $this->db->parameter("country_name",$data["country_name"]);
              $this->db->parameter("country_code",$data["country_code"]);
              $ins   = $this->db->fetch();
          }

          public function updateCountry(array $data, int $id){
              $upd = $this->db->update("countries")
                              ->set(["country_name", "country_code"])
                              ->where("countries_id = id")
                              ->x();

              $this->db->parameter("country_name",$data["country_name"]);
              $this->db->parameter("country_code",$data["country_code"]);
              $this->db->parameter("id",$id);
              $this->db->fetch();
          }

          public function deleteCountry(int $id){
              $this->db->delete("countries")->where("countries_id = id")->x();
              $this->db->parameter("id",$id);
              $this->db->fetch();
          }
      }
  }

The View

We will create Three views

  1. Add View
  2. Edit View
  3. Index View
<!-- Add View -->
<?php $this->inc('themes/pages/page_start'); ?>
<?php $this->inc('themes/navigation/admin') ?>

<section id="page" class="section-padding mx-4">
    <div class="container">
        <div class="card padding-card">
            <div class="card-body">
                <h5 class="card-title mb-4">Country Configuration</h5>
                <form id="countryEditForm" method="post">
                    <div class="form-row">
                        <div class="col-sm-4">
                            <div class="form-group">
                                <label>Country Name:</label>
                                <input type="text" name="country_name" id="country_name"  class="form-control"/>
                            </div>
                            <div class="form-group">
                                <label>Country Code:</label>
                                <input type="text" name="country_code" id="country_code" class="form-control"/>
                            </div>
                            <div class="form-group">
                                <a href="#" class="btn btn-primary" name="save" data-action="save">Save</a>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</section>

<?php $this->inc('themes/pages/page_end'); ?>
    //Script for Add View
    $(document).ready(function(){
        $("a").click(function(){
            switch($(this).attr("name")){
                case "save":
                    $.ajax({
                        "url": base_url + 'admin/country/xhrAdd/',
                        "type": "POST",
                        "data": $("#countryEditForm").serialize(),
                        "success":function(result){
                        },
                    });
                break;
            }
        });
    });
<!-- Edit View -->
<?php $this->inc('themes/pages/page_start'); ?>
<?php $this->inc('themes/navigation/admin') ?>
<?php $id = $this->get("id"); ?>

<section id="page" class="section-padding mx-4">
    <div class="container">
        <div class="card padding-card">
            <div class="card-body">
                <h5 class="card-title mb-4">Country Configuration</h5>
                <form id="countryEditForm" method="post">
                    <div class="form-row">
                        <div class="col-sm-4">
                            <div class="form-group">
                                <label>Country ID:</label>
                                <input type="text" name="countries_id" id="countries_id" value="<?php echo $id; ?>" class="form-control" disabled />
                            </div>
                            <div class="form-group">
                                <label>Country Name:</label>
                                <input type="text" name="country_name" id="country_name"  class="form-control"/>
                            </div>
                            <div class="form-group">
                                <label>Country Code:</label>
                                <input type="text" name="country_code" id="country_code"  class="form-control"/>
                            </div>
                            <div class="form-group">
                                <a href="#" class="btn btn-primary" name="back">Back</a>
                                <a href="#" class="btn btn-primary" name="save" data-action="save">Save</a>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</section>

<?php $this->inc('themes/pages/page_end'); ?>
    //Script for Edit View
    $(document).ready(function(){
        var id;
        id = $("#countries_id").val();
        $.ajax({
            "url": base_url + 'admin/country/xhrGetIndexByID/' + id,
            "type": "GET",
            "success":function(result){
                $("#country_name").val(result[0]["country_name"]);
                $("#country_code").val(result[0]["country_code"]);
            },
        });

        $("a").on("click",function(e){
            e.preventDefault();
            switch($(this).attr("name")){
                case "save":
                    $.ajax({
                        "url": base_url + 'admin/country/xhrUpdate/' + id,
                        "type": "POST",
                        "data": $("#countryEditForm").serialize(),
                        "success":function(result){
                        },
                    });
                break;
            }
        });
    });
<!-- Index View -->
<?php $this->inc('themes/pages/page_start'); ?>
<?php $this->inc('themes/navigation/admin') ?>
<?php $this->inc('themes/style.fix') ?>

<!-- Overlay Navigation -->
<div class="slider-overlay"></div>
<section id="page" class="section-padding mx-4">
    <div class="grid-container">
        <div class="grid-row">
            <div class="grid-item item-xs-12">
                <div >
                </div>
                <div class="tables-widget tables-widget-default tables-widget-blue tables-widget-striped">
                <div class="tables-widget-header"></div>
                    <table width="100%" id="master-list" class="table table-striped table-bordered">
                        <thead>
                            <tr>
                                <th>Country ID
                                    <i class="icomoon-menu-open"></i>
                                </th>
                                <th>Country Name
                                    <i class="icomoon-menu-open"></i>
                                </th>
                                <th>Country Code
                                    <i class="icomoon-menu-open"></i>
                                </th>
                                <th>Action
                                    <i class="icomoon-menu-open"></i>
                                </th>
                            </tr>
                        </thead>
                        <tfoot>
                            <tr></tr>
                        </tfoot>
                    </table>
                </div>
            </div>
        </div>
    </div>
</section>

<?php $this->inc('themes/pages/page_end'); ?>
<?php $this->js("static","pages/admin/country")?>

The conclusion

PHP Shark is a Portal Application Framework . It is capable of connecting to All sort of Web Based Application with its servers and Services. We will now explore all the unexplained functions and concepts in the upcoming sections one-by-one.

The Example of a country page is the most basic example that includes All routing, CRUD and Interfaces. There is more to it. You can use all RAW PHP, or create your own customer functions or use the standard ones available via framework.

So here it is, A projection of a working page. Your project file has a template Section. Well, sometimes there are few sections which are repeatedly occurring on all the pages. They can be Header, footer, menus or anything. These templates can be created and stored inside this template folder and called via inc function. oh! don't bother about the name, its simply the folder creation and their names.

 <?php 
 $this->inc(themes/pages/page_start);

Wish you a Happy Coding!! :)

Document Structure

PHP Shark Document Structure.

Inside the folder here you will see three basic folders and some files laying inside the root folder.

App Folder

In order, not to break the application - I would not recommend you to touch this folder and files inside of it. reason being this is the application folder and there will be a lot of changes and upgrades to this folder as the application moves on in its course of deployment. If you feel like debugging and dig this application, please be my guest, but that doesn't guarantee a hassle free upgrade. you can just open a a pull request to make amendments or even contribute to a big fix.

Project Folder

This folder is your version of APP folder. This is where you can create you customer copies and libraries for your PHP project. All the changes are recommended to reside inside the project folder. This is the folder that contains you files Router and configuration files as well. The two files are mandatory files required by the application.

Public Folder

This is public repository of you project. When the folder is deployed, this is where you public accessible files like - CSS/JS and other public assets are placed.

Src Folder

This is were all the magic happens - all links, models, controllers and you view files resides inside this folder. This folder is the driver of you portal.

.htaccess file

Options +FollowSymLinks +ExecCGI
<IfModule mod_rewrite.c>
   RewriteEngine on
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteCond %{REQUEST_FILENAME} !-l
   RewriteCond %{REQUEST_URI}  !(\.png|\.jpg|\.gif|\.jpeg|\.bmp)$ [NC]

   RewriteRule   (.*) index.php?url=$1  [QSA,L]

   Options -Indexes
</IfModule>

Controller & Functions

request

isPost()

@Parameter: none

Checks if the HTTP request is POST.

@return: boolean

<?php
//Request::Public
$this->request->isPost();

isGet()

@Parameter: none

Checks if the HTTP request is GET.

@return: boolean

<?php
//Request::Public
$this->request->isGet();

getServerMethod()

@Parameter: none

Returns the server method - POST, GET or PUT.

@return: boolean

<?php
//Request::Public
$this->request->getServerMethod();

set(Array)

Cookie Setup.

@Parameter: Array $opt

@Mandatory: $opt["name"]

Cookie Name is required.

@Mandatory: $opt["value"]

Cookie Value is required.

@return: null

<?php
//Cookie::Public
$this->cookie->set($opt);

isCookieEnabled()

Checks if Cookie is Enabled.

@Parameter: None

@return: boolean

<?php
//Cookie::Public
$this->cookie->isCookieEnabled();

unset(Array)

Cookie Setup.

@Parameter: Array $opt

@Mandatory: $opt["name"]

Cookie Name is required.

@Mandatory: $opt["value"]

Cookie Value is required.

@return: null

<?php
//Cookie::Public
$this->cookie->unset($opt);

paginate

getDetails

@Parameter: Int $total

@Mandatory: true

Specify total number of pages.

@Parameter: Int $page_number

@Default: 1

Starting Page Number.

@Parameter: Int $limit

@Default: 10

Maximum pages.

@Parameter: Int $per_page

@Default: 1

Items Per Page.

@return: Array $calculation

<?php
//Paginate::Public
$this->paginate->getDetails(
            $total,
            $page_number = 1,
            $columns = 3,
            $limit = 10,
            $per_page = 1
        );

ifCookieIsEnabled()

protected::function ifCookieIsEnabled()

checks if cookie is enabled.

@return: boolean

<?php
//Check if Cookie is enabled
//Protected
$this->ifCookieIsEnabled();

protected::function isLoggable(string)

@Parameter: String $model_function

It calls the model function with the $_COOKIE parameter.

@return: instance

Description: Check if Cookie is log-able.

Tag Description
COOLKIE_EXPIRY Sets the Cookie Expiry time. Default: 604800.
<?php
//Protected
$this->isLoggable($model_function);

redirect()

protected::function redirect(string = null)

Redirect the page to another URL.

@Parameter: String $link

Relative link as a parameter which appears after the base url configured in the config.xml.

@return: null

<?php
//Protected
$this->redirect($link);

phpMailer()

protected::function phpMailer(string = null, string = null)

PHP Mail function.

@Parameter: String $address

Email Address of the Recipient

@Parameter: String $type

Address Type

@return: object

Tag Description
MAIL_HOST Set the SMTP Host.
MAIL_USER Set the SMTP User. Usually the sender Address.
MAIL_PASSWORD User Password.
MAIL_SMTP_SECURE SMTP Secure Layer Protocol.
MAIL_PORT Sets the mail port.
MAIL_SET_FROM Sets the Email Sent from.
MAIL_SET_FROM_TYPE Set the Sender's Mail type
MAIL_SMTP_AUTH SMTP Authorisation.
TEMPLATE_FOLDER Email Template Folder.

The extensive documentation will be found here

<?php
//Protected
$this->phpMailer($addr,$type);

json_out()

protected::function json_out(string, string = null)

Output the JSON format at controller level.

@Parameter: String $data

Output JSON Data

@Parameter: String $variable

Output JSON with an associated name.

@return: JSON Output | NULL

<?php
//Protected
$this->redirect($data, $variable);

getView()

protected::function getView(string)

Alternate Controller Call to View::Render function.

@return: NULL

<?php
//Protected
$this->getView($viewname);

getModel()

protected::function getModel($args)

Alternate Controller Call to its Model functions.

@return: Mixed

<?php
//Protected
$this->getModel($args);

Model & Functions

set(Array)

Cookie Setup.

@Parameter: Array $opt

@Mandatory: $opt["name"]

Cookie Name is required.

@Mandatory: $opt["value"]

Cookie Value is required.

@return: null

<?php
//Cookie::Public
$this->cookie->set($opt);

isCookieEnabled()

Checks if Cookie is Enabled.

@Parameter: None

@return: boolean

<?php
//Cookie::Public
$this->cookie->isCookieEnabled();

unset(Array)

Cookie Setup.

@Parameter: Array $opt

@Mandatory: $opt["name"]

Cookie Name is required.

@Mandatory: $opt["value"]

Cookie Value is required.

@return: null

<?php
//Cookie::Public
$this->cookie->unset($opt);

files

fileContent(String);

Reads the file content form the given url path.

@Parameter: String $url / $path

@Mandatory: String $url / $path

@return: Text | Object | Mixed.

<?php
//files::Public
$this->files->fileContent($url);

fileContent(String);

checks if the file exist.

@Parameter: String $file_path

@Mandatory: String $file_path

@return: boolean.

<?php
//files::Public
$this->files->fileExist($file_path);

fileSize(String);

returns the file size.

@Parameter: String $upload_file_name_attr

@Mandatory: String $upload_file_name_attr

specify the name attribute of the upload form field.

@return: int.

<?php
//files::Public
$this->files->fileSize($upload_file_name_attr);

fileName(String);

returns the file name.

@Parameter: String $upload_file_name_attr

@Mandatory: String $upload_file_name_attr

specify the name attribute of the upload form field.

@return: string.

<?php
//files::Public
$this->files->fileName($upload_file_name_attr);

fileType(String);

returns the file type.

@Parameter: String $upload_file_name_attr

@Mandatory: String $upload_file_name_attr

specify the name attribute of the upload form field.

@return: string.

<?php
//files::Public
$this->files->fileType($upload_file_name_attr);

fileInfo(String);

returns the file mata information.

@Parameter: String $target_file

@Mandatory: String $target_file

@return: string.

<?php
//files::Public
$this->files->fileInfo($target_file);

imageSize(string);

returns the image size.

@Parameter: String $upload_file_name_attr

@Mandatory: String $upload_file_name_attr

specify the name attribute of the upload form field.

@return: string.

<?php
//files::Public
$this->files->imageSize($upload_file_name_attr);

isImage(string);

check if it is a valid image.

@Parameter: String $upload_file_name_attr

@Mandatory: String $upload_file_name_attr

specify the name attribute of the upload form field.

@return: boolean.

<?php
//files::Public
$this->files->isImage($upload_file_name_attr);

isFile(string);

check if it is a valid file.

@Parameter: String $upload_file_name_attr

@Mandatory: String $upload_file_name_attr

specify the name attribute of the upload form field.

@return: boolean.

<?php
//files::Public
$this->files->isFile($upload_file_name_attr);

createFolder(string);

creates a folder at the target location.

@Parameter: String $target

@Mandatory: String $target

@return: boolean.

<?php
//files::Public
$this->files->createFolder($target);

putFileContent(array_list);

creates a folder at the target location.

@Parameter: Array[0] $target

@Mandatory: Array[0] $target

specify the target location.

@Parameter: Array[1] $content

@Mandatory: Array[1] $content

specify the content of the file.

@return: boolean.

<?php
//files::Public
$this->files->putFileContent($target,$content);

fileRename(string, string, string);

renames a file.

@Parameter: string $location

@Mandatory: string $location

specify the target location.

@Parameter: string $old

@Mandatory: string $old

specify the old name.

@Parameter: string $new

@Mandatory: string $new

specify the new name.

@return: boolean.

<?php
//files::Public
$this->files->fileRename($location, $old, $new);

fileDelete(string);

deletes a file at target location.

@Parameter: string $target_file

@Mandatory: string $target_file

specify the target location.

@return: boolean.

<?php
//files::Public
$this->files->fileDelete($target_file);

fileMode(string);

change the file mode.

@Parameter: string $target_file

@Mandatory: string $target_file

@return: boolean.

<?php
//files::Public
$this->files->fileMode($target_file);

getChangeGroup(string, string);

change file the file group.

@Parameter: string $target_file

@Mandatory: string $target_file

specify the target location.

@Parameter: string $group

@Mandatory: string $group

specify the file group.

@return: boolean.

<?php
//files::Public
$this->files->getChangeGroup($upload_file_name_attr, $target_file);

fileUploadToServer(string, string);

uploads the file to a target location.

@Parameter: string $upload_file_name_attr

@Mandatory: string $upload_file_name_attr

specify the name attribute of the upload form field.

@Parameter: string $target_file

@Mandatory: string $target_file

specify the target location.

@return: boolean.

<?php
//files::Public
$this->files->imgUpload($upload_file_name_attr, $target_file);

image

imgUpload();

Puts the file into the file location "target_original" into the configuration file.

<?php
//image::Public
$this->image->imgUpload();

fileDelete(String);

deletes the file from the location.

@Parameter: string $target_file

@Mandatory: string $target_file

specify the target location.

<?php
//image::Public
$this->image->fileDelete($target_file);

imgResize(int, int, boolean);

Resize Image File.

@Parameter: int $width

@Mandatory: int $width

specify the width of the image.

@Parameter: int $height

@Mandatory: int $height

specify the height of the image.

@Parameter: int $state

@Default: true

Upload original file or not.

<?php
//image::Public
$this->image->imgResize($width, $height, $state);

reCreateFile(string, string, int, int, string, string);

Recreate the Image File

@Parameter: string $target_file

@Mandatory: string $target_file

specify the target location.

@Parameter: string $resized_file

@Mandatory: string $resized_file

specify the resized location.

@Parameter: int $width

@Mandatory: int $width

specify the width of the image.

@Parameter: int $height

@Mandatory: int $height

specify the height of the image.

@Parameter: string $ext

@Mandatory: string $ext

specify the extension of the file.

@Parameter: string $activity

@Default: null

specify activity like Ex. crop

<?php
//image::Public
$this->image->reCreateFile($target_file, $resized_file, $width, $height, $ext, $activity);

removeTempFile(string);

Remove temporary file.

@Parameter: string $path

@Mandatory: string $path

<?php
//image::Public
$this->image->removeTempFile($path);

imgWatermark(string, string);

Creates a Water Mark on image file.

@Parameter: string $wtrmrk_file

@Mandatory: string $wtrmrk_file

Watermark File.

@Parameter: string $path

@default:null

Path of the watermark file.

<?php
//image::Public
$this->image->imgWatermark($wtrmrk_file, $path);

upload

x(array_list);

Execute Upload

@Parameter: Array $opt

@Mandatory: Array $opt

Array of options.

@Parameter: string $opt["attribute-name"]

@Mandatory: string $opt["attribute-name"]

specify upload field arrtibute.

@Parameter: string $opt["location"]

@Mandatory: string $opt["location"]

specify upload location.

@Parameter: int $opt["size-limit"]

limit the upload size by specification.

@Parameter: string $opt["allowed-type"]

upload file allowed type.

@default:boolean

<?php
//upload::Public
$this->upload->x($opt);

tempalate

get_template(string, string);

it is a utility provided via "project Folder" to maintain the mail templates separately and pull them to PHP mails from multiple locations.

@Parameter: string $location

@Mandatory: string $location

specify the location of the file relative from project template.

@Parameter: string $name

@Mandatory: string $name

specify the template name.

json

writeJSONFile(string, string, boolean, string )

@Paramater: string $row

@Mandatory: string $row

Write JSON Output to a file. The output file is saved to project folder > warehousing > $filePathOrName

@Paramater: string $name

@Default: null

specify the file name.

@Paramater: boolean $object

@Default: true

The Output Json Object.

@Paramater: string $path

@Default: null

Path is relative to Project > Migration.

@return: boolean $state

<?php
$this->json->writeJSONFile($row, $name, $object, $path);

readJSONFile(string, string )

Read JSON Output to a file. The output file is read from project folder > warehousing > $filePathOrName

@Paramater: string $name

@Default: null

specify the filename

@Paramater: boolean $object

@Default: true

The Output Json Object.

@Paramater: string $path

@Default: null

Path is relative to Project > Migration.

@return: array $json

<?php
$this->json->readJSONFile($name, $path);

searchReadJSONFile(string, string, string, string )

@Paramater: string $key

@Mandatory: string $key

Read JSON Output to a file with key and matching value

@Paramater: string $value

@Mandatory: string $value

Match value string

@Paramater: string $name

@Default: null

@Paramater: string $path

@Default: null

Path is relative to Project > Migration.

@return: string $value

<?php
$this->json->writeJSONFile($key, $value, $name, $path);

JsonAPIValues(string)

Decodes JSON from the given URL.

@Paramater: string $url.

@Mandatory: $url.

API Path.

@return: object $json

<?php
$this->json->JsonAPIValues($url);

encode(array, int)

Encode JSON Object.

@Paramater: array $result.

@Mandatory: $result.

@Paramater: int $option.

@Default: 0.

Json_encode Options

<?php
$this->json->encode($result, $option);

decode(string, boolean)

Decodes JSON Object.

@Paramater: string $url.

@Mandatory: $url.

@Paramater: boolean $assoc.

@Default: false.

<?php
$this->json->decode($url, $assoc);

output(array, string)

Encode JSON Object for http request.

@Paramater: array $result.

@Mandatory: $result.

Result Output.

@Paramater: string $charset.

@default: UTF-8.

Character Encoding.

<?php
$this->json->output($result,$charset);

Model view

set(string, mixed)

Sets the value coming from model into the view variables

@parameter: String $var_name (Mandatory)

@parameter: String $var_value (Mandatory)

<?php
$this->view->set($name,$value);

title(string)

Set the title of the page at controller level.

@parameter: String $page_title (Mandatory)

<?php
$this->view->title($page_title);

render(string)

Render the page.

@parameter: String $page_name (Mandatory)

<?php
$this->view->render($page_name);

Query & CRUD Functions

pdo

pdo()

Get PDO Instance.

@patameter: null

is_field

is_field(string, string, string)

Check if the field exist in database.

@parameter: string $table Mandatory

@parameter: string $field Mandatory

@parameter: string $db Default: Null

@return boolean.

  <?php
  \orm\Query::is_field($table, $field, $db);

is_table

is_table(string, string)

Check if the table exist in database.

@parameter: string $table (Mandatory)

@parameter: string $db (Default: Null)

@return boolean.

  <?php
  \orm\Query::is_table($table, $db);

keyFields

keyFields(string, PDO Class)

Get all key field of the table.

@parameter: string $table (Mandatory)

@parameter: PDO Class $fetchMode (Default: PDO::FETCH_ASSOC)

  <?php
  \orm\Query::keyFields($db, $class);

Select

The SELECT statement is used to select data from a database. The data returned is stored in a result table, called the result-set.

SELECT * FROM table_name

  <?php
  $this->db->select()->from("users")->x();
  $sel = $this->db->fetch();

  //$sel holds the object.

where

The WHERE clause is used to filter records.

The WHERE clause is used to extract only those records that fulfill a specified condition.

SELECT column1, column2 FROM table_name WHERE user_id = 1;

  <?php
  //SELECT column1, column2 FROM table_name WHERE user_id = 1;

   $this->db->select(["name1", "name2"])
            ->from("users")
            ->where("user_id = id")->x();

  $this->db->parameter("id",1);
  $sel = $this->db->fetch();

  //$sel holds the object.

SELECT * FROM Customers WHERE Country='Germany' AND City='Berlin';

  <?php
  //SELECT * FROM Customers WHERE Country='Germany' AND City='Berlin';

   $this->db->select()
            ->from("Customers")
            ->where("Country = i_country")
            ->and("City = i_city")->x();

  $this->db->parameter("i_country",'Germany');
  $this->db->parameter("i_city",'Berlin');
  $sel = $this->db->fetch();

  //$sel holds the object.

SELECT * FROM Customers WHERE City='Berlin' OR City='München';

  <?php
  //SELECT * FROM Customers WHERE City='Berlin' OR City='München';

   $this->db->select()
            ->from("Customers")
            ->where("City = i_city1")
            ->or("City = i_city2")->x();

  $this->db->parameter("i_city1",'Berlin');
  $this->db->parameter("i_city2",'München');
  $sel = $this->db->fetch();

  //$sel holds the object.

SELECT * FROM Customers WHERE NOT Country='Germany';

  <?php
  //SELECT * FROM Customers WHERE NOT Country='Germany';

   $this->db->select()
            ->from("Customers")
            ->whereNot("Country = i_country")->x();

  $this->db->parameter("i_country",'Germany');
  $sel = $this->db->fetch();

  //$sel holds the object.

SELECT * FROM Customers WHERE Country='Germany' AND (City='Berlin' OR City='München');

  <?php
  //SELECT * FROM Customers WHERE Country='Germany' AND (City='Berlin' OR City='München');

   $this->db->select()
            ->from("Customers")
            ->where("Country = i_country")
            ->and("city = i_city1")
            ->or("city = i_city2")->x();

  $this->db->parameter("i_country",'Germany');
  $this->db->parameter("i_city1",'Berlin');
  $this->db->parameter("i_city2",'München');
  $sel = $this->db->fetch();

  //$sel holds the object.

SELECT * FROM Customers WHERE NOT Country='Germany' AND NOT Country='USA';

  <?php
   //SELECT * FROM Customers WHERE NOT Country='Germany' AND NOT Country='USA';

   $this->db->select()
            ->from("Customers")
            ->whereNot("Country = i_country1")
            ->andNot("Country = i_country2")->x();

  $this->db->parameter("i_country1",'Germany');
  $this->db->parameter("i_country1",'USA');
  $sel = $this->db->fetch();

  //$sel holds the object.

null values

A field with a NULL value is a field with no value.

If a field in a table is optional, it is possible to insert a new record or update a record without adding a value to this field. Then, the field will be saved with a NULL value.

SELECT LastName, FirstName, Address FROM Persons WHERE Address IS NULL;

  <?php
   /*SELECT LastName, FirstName, Address FROM Persons
   WHERE Address IS NULL;*/

   $this->db->select(["LastName", "FirstName", "Address"])
            ->from("Persons")->is_null("address")
            ->->x();

  $this->db->parameter("i_country1",'Germany');
  $this->db->parameter("i_country1",'USA');
  $sel = $this->db->fetch();

  //$sel holds the object.

SELECT LastName, FirstName, Address FROM Persons WHERE Address IS NOT NULL;

  <?php
   /*SELECT LastName, FirstName, Address FROM Persons
   WHERE Address IS NOT NULL;*/

   $this->db->select(["LastName", "FirstName", "Address"])
            ->from("Persons")->is_null("address", false)
            ->->x();

  $this->db->parameter("i_country1",'Germany');
  $this->db->parameter("i_country1",'USA');
  $sel = $this->db->fetch();

  //$sel holds the object.

Select Columns

SELECT CustomerName, City FROM Customers

  <?php
  //SELECT CustomerName, City FROM Customers

  $this->db->select(["CustomerName", "City"])->from("Customers")->x();
  $sel = $this->db->fetch();

  //$sel holds the object.

Select Distinct

The SELECT DISTINCT statement is used to return only distinct (different) values.

Inside a table, a column often contains many duplicate values; and sometimes you only want to list the different (distinct) values.

The SELECT DISTINCT statement is used to return only distinct (different) values.

SELECT DISTINCT Country FROM Customers;

  <?php
  //SELECT DISTINCT Country FROM Customers;

  $this->db->distinct(["CustomerName"])->from("Customers")->x();
  $sel = $this->db->fetch();

  //$sel holds the object.

Select Distinct Count

SELECT COUNT(DISTINCT Country) FROM Customers;

  <?php
  //SELECT COUNT(DISTINCT Country) FROM Customers;

  $this->db->count_distinct(["CustomerName"])->from("Customers")->x();
  $sel = $this->db->fetch();

  //$sel holds the object.

Select Order By

The ORDER BY keyword is used to sort the result-set in ascending or descending order.

The ORDER BY keyword sorts the records in ascending order by default. To sort the records in descending order, use the DESC keyword.

SELECT * FROM Customers ORDER BY Country;

  <?php
  //SELECT * FROM Customers ORDER BY Country;

  $this->db->select()->from("Customers")->orderBy('Country')->x();
  $sel = $this->db->fetch();

  //$sel holds the object.

SELECT * FROM Customers ORDER BY Country DESC;

  <?php
  //SELECT * FROM Customers ORDER BY Country DESC;

  $this->db->select()->from("Customers")->orderBy("Country","DESC")->x();
  $sel = $this->db->fetch();

  //$sel holds the object.

SELECT * FROM Customers ORDER BY Country, CustomerName;

  <?php
  //SELECT * FROM Customers ORDER BY Country, CustomerName;

  $this->db->select()->from("Customers")->orderBy(["Country","CustomerName"])->x();
  $sel = $this->db->fetch();

  //$sel holds the object.

SELECT * FROM Customers ORDER BY Country ASC, CustomerName DESC;

  <?php

  //SELECT * FROM Customers ORDER BY Country ASC, CustomerName DESC;

  $this->db->select()->from("Customers")
                     ->orderBy(["Country ASC","CustomerName DESC"])->x();
  $sel = $this->db->fetch();

  //$sel holds the object.

limit

The LIMIT clause is used to specify the number of records to return.

The LIMIT clause is useful on large tables with thousands of records. Returning a large number of records can impact on performance.

SELECT * FROM Customers LIMIT 3;

  <?php

  //SELECT * FROM Customers LIMIT 3;

  $this->db->select()->from("Customers")->limit(3)->x();

  $sel = $this->db->fetch();

  //$sel holds the object.

min

The MIN() function returns the smallest value of the selected column.

SELECT MIN(Price) AS SmallestPrice FROM Products;

  <?php

  //SELECT MIN(Price) AS SmallestPrice FROM Products;

  $this->db->function("Min","Price")->as("SmallestPrice")->from("Products")->x();

  $sel = $this->db->fetch();

  //$sel holds the object.

max

The MAX() function returns the largest value of the selected column.

SELECT MAX(Price) AS SmallestPrice FROM Products;

  <?php

  //SELECT MIN(Price) AS SmallestPrice FROM Products;

  $this->db->function("Min","Price")->as("SmallestPrice")->from("Products")->x();

  $sel = $this->db->fetch();

  //$sel holds the object.

count

The COUNT() function returns the number of rows that matches a specified criteria.

SELECT COUNT(ProductID) FROM Products;

  <?php

  //SELECT MIN(Price) AS SmallestPrice FROM Products;

  $this->db->function("Count","ProductID")->from("Products")->x();

  $sel = $this->db->fetch();

  //$sel holds the object.

avg

The AVG() function returns the average value of a numeric column.

SELECT AVG(Price) FROM Products;

  <?php

  //SELECT AVG(Price) FROM Products;

  $this->db->function("AVG","Price")->from("Products")->x();

  $sel = $this->db->fetch();

  //$sel holds the object.

sum

The SUM() function returns the total sum of a numeric column.

SELECT SUM(Quantity) FROM OrderDetails;

  <?php

  //SELECT SUM(Quantity) FROM OrderDetails;

  $this->db->function("SUM","Quantity")->from("OrderDetails")->x();

  $sel = $this->db->fetch();

  //$sel holds the object.

like

The LIKE operator is used in a WHERE clause to search for a specified pattern in a column.

There are two wildcards used in conjunction with the LIKE operator:

% - The percent sign represents zero, one, or multiple characters _ - The underscore represents a single character

Note: MS Access uses a question mark (?) instead of the underscore (_)

LIKE Operator Description
WHERE CustomerName LIKE 'a%' Finds any values that starts with "a"
WHERE CustomerName LIKE '%a' Finds any values that ends with "a"
WHERE CustomerName LIKE '%or%' Finds any values that have "or" in any position
WHERE CustomerName LIKE '_r%' Finds any values that have "r" in the second position
WHERE CustomerName LIKE 'a_%_%' Finds any values that starts with "a" and are at least 3 characters in length
WHERE ContactName LIKE 'a%o' Finds any values that starts with "a" and ends with "o"

SELECT * FROM Customers WHERE CustomerName LIKE 'a%';

  <?php

  //SELECT * FROM Customers WHERE CustomerName LIKE 'a%';

  $this->db->select()->from("Customers")
           ->where("CustomerName LIKE name")->x();

  $this->db->parameter("name",'a%');       

  $sel = $this->db->fetch();

  //$sel holds the object.

SELECT * FROM Customers WHERE CustomerName LIKE '%a';

  <?php

  //SELECT * FROM Customers WHERE CustomerName LIKE '%a';

  $this->db->select()->from("Customers")
           ->where("CustomerName LIKE name")->x();

  $this->db->parameter("name",'%a');       

  $sel = $this->db->fetch();

  //$sel holds the object.

SELECT * FROM Customers WHERE CustomerName LIKE '%or%';

  <?php

  //SELECT * FROM Customers WHERE CustomerName LIKE '%or%';

  $this->db->select()->from("Customers")
           ->where("CustomerName LIKE name")->x();

  $this->db->parameter("name",'%or%');       

  $sel = $this->db->fetch();

  //$sel holds the object.

SELECT * FROM Customers WHERE CustomerName LIKE '_r%';

  <?php

  //SELECT * FROM Customers WHERE CustomerName LIKE '_r%';

  $this->db->select()->from("Customers")
           ->where("CustomerName LIKE name")->x();

  $this->db->parameter("name",'_r%');       

  $sel = $this->db->fetch();

  //$sel holds the object.

SELECT * FROM Customers WHERE CustomerName LIKE 'a_%_%';

  <?php

  //SELECT * FROM Customers WHERE CustomerName LIKE 'a_%_%';

  $this->db->select()->from("Customers")
           ->where("CustomerName LIKE name")->x();

  $this->db->parameter("name",'a_%_%');       

  $sel = $this->db->fetch();

  //$sel holds the object.

SELECT * FROM Customers WHERE CustomerName LIKE 'a%o';

  <?php

  //SELECT * FROM Customers WHERE CustomerName LIKE 'a%o';

  $this->db->select()->from("Customers")
           ->where("CustomerName LIKE name")->x();

  $this->db->parameter("name",'a%o');       

  $sel = $this->db->fetch();

  //$sel holds the object.

in

The IN operator allows you to specify multiple values in a WHERE clause.

The IN operator is a shorthand for multiple OR conditions.

SELECT * FROM Customers WHERE Country IN ('Germany', 'France', 'UK');

  <?php

  //SELECT * FROM Customers WHERE Country IN ('Germany', 'France', 'UK');

  $this->db->select()->from("Customers")
           ->in("Country",["name1", "name2", "name3"])->x();

  $this->db->parameter("name1",'Germany');   
  $this->db->parameter("name2",'France');   
  $this->db->parameter("name3",'UK');       

  $sel = $this->db->fetch();

  //$sel holds the object.

SELECT * FROM Customers WHERE Country IN (SELECT Country FROM Suppliers);

  <?php

  /* SELECT * FROM Customers
    WHERE Country IN (SELECT Country FROM Suppliers); */

  $this->db->select()->from("Customers")
           ->in("Country", "SELECT Country FROM Suppliers" )->x();
  $sel = $this->db->fetch();

  //$sel holds the object.

between

The BETWEEN operator selects values within a given range. The values can be numbers, text, or dates.

The BETWEEN operator is inclusive: begin and end values are included.

SELECT * FROM Products WHERE Price BETWEEN 10 AND 20;

  <?php

  /* SELECT * FROM Products WHERE Price BETWEEN 10 AND 20; */

  $this->db->select()->from("Products")
           ->where_between("Country", "value1", "value2")->x();

  $this->db->parameter("value1",10);  
  $this->db->parameter("value2",20);  
  $sel = $this->db->fetch();

  //$sel holds the object.

SELECT * FROM Products WHERE Price NOT BETWEEN 10 AND 20;

  <?php

  /* SELECT * FROM Products WHERE Price NOT BETWEEN 10 AND 20; */

  $this->db->select()->from("Products")
           ->where_not_between("Country", "value1", "value2")->x();

  $this->db->parameter("value1",10);  
  $this->db->parameter("value2",20);  
  $sel = $this->db->fetch();

  //$sel holds the object.

SELECT * FROM Products WHERE (Price BETWEEN 10 AND 20) AND NOT CategoryID IN (1,2,3);

  <?php

  /* SELECT * FROM Products WHERE (Price BETWEEN 10 AND 20)
                          AND NOT CategoryID IN (1,2,3); */

  $this->db->select()->from("Products")
           ->where_between("Price", "value1", "value2")
           ->and_not_in("CategoryID",["value3","value4","value5"])
           ->x();

  $this->db->parameter("value1",10);  
  $this->db->parameter("value2",20);  
  $this->db->parameter("value3",1);  
  $this->db->parameter("value4",2);  
  $this->db->parameter("value5",3);  
  $sel = $this->db->fetch();

  //$sel holds the object.

SELECT * FROM Products WHERE ProductName BETWEEN 'Carnarvon Tigers' AND 'Mozzarella di Giovanni' ORDER BY ProductName;

<?php

/* SELECT * FROM Products
   WHERE ProductName BETWEEN 'Carnarvon Tigers' AND 'Mozzarella di Giovanni'
   ORDER BY ProductName; */

$this->db->select()->from("Products")
         ->where_between("ProductName", "value1", "value2")
         ->orderBy("ProductName")
         ->x();

$this->db->parameter("value1","Carnarvon Tigers");  
$this->db->parameter("value2","Mozzarella di Giovanni");  
$sel = $this->db->fetch();

//$sel holds the object.

SELECT * FROM Products WHERE ProductName NOT BETWEEN 'Carnarvon Tigers' AND 'Mozzarella di Giovanni' ORDER BY ProductName;

<?php

/* SELECT * FROM Products
   WHERE ProductName NOT BETWEEN 'Carnarvon Tigers' AND 'Mozzarella di Giovanni'
   ORDER BY ProductName; */

$this->db->select()->from("Products")
         ->where_not_between("ProductName", "value1", "value2")
         ->orderBy("ProductName")
         ->x();

$this->db->parameter("value1","Carnarvon Tigers");  
$this->db->parameter("value2","Mozzarella di Giovanni");  
$sel = $this->db->fetch();

//$sel holds the object.

alias

SQL aliases are used to give a table, or a column in a table, a temporary name.

Aliases are often used to make column names more readable.

An alias only exists for the duration of the query.

SELECT CustomerID as ID, CustomerName AS Customer FROM Customers;

<?php
/* SELECT CustomerID as ID, CustomerName AS Customer FROM Customers; */

$this->db->select(["CustomerID as ID","CustomerName AS Customer"])
         ->from("Customers")
         ->x();

$sel = $this->db->fetch();

//$sel holds the object.

SELECT CustomerName AS Customer, ContactName AS [Contact Person] FROM Customers;

<?php

/* SELECT CustomerName AS Customer, ContactName AS [Contact Person]
FROM Customers; */

$this->db->select(["CustomerName as Customer","ContactName as [Contact Person]"])
         ->from("Customers")
         ->x();

$sel = $this->db->fetch();

//$sel holds the object.

SELECT CustomerName, Address + ', ' + PostalCode + ' ' + City + ', ' + Country AS Address FROM Customers;

<?php

/* SELECT CustomerName, Address + ', ' + PostalCode + ' ' + City + ', ' + Country AS Address
FROM Customers; */

$this->db->select(["CustomerName","Address + ', ' + PostalCode + ' ' + City + ', ' + Country AS Address"])
         ->from("Customers")
         ->x();

$sel = $this->db->fetch();

//$sel holds the object.

SELECT o.OrderID, o.OrderDate, c.CustomerName FROM Customers AS c, Orders AS o WHERE c.CustomerName="Around the Horn" AND c.CustomerID=o.CustomerID;

<?php

/* SELECT o.OrderID, o.OrderDate, c.CustomerName FROM Customers AS c, Orders AS o
WHERE c.CustomerName="Around the Horn" AND c.CustomerID=o.CustomerID; */

$this->db->select(["o.OrderID", "o.OrderDate", "c.CustomerName"])
         ->from("Customers AS c, Orders AS o")
         ->where("c.CustomerName = cus_name")
         ->and("c.CustomerID = o.CustomerID")
         ->x();

$sel = $this->db->parameter("cus_name","Around the Horn");
$sel = $this->db->fetch();

//$sel holds the object.

SELECT Orders.OrderID, Orders.OrderDate, Customers.CustomerName FROM Customers, Orders WHERE Customers.CustomerName="Around the Horn" AND Customers.CustomerID=Orders.CustomerID;

<?php

/* SELECT o.OrderID, o.OrderDate, c.CustomerName FROM Customers AS c, Orders AS o
WHERE c.CustomerName="Around the Horn" AND c.CustomerID=o.CustomerID; */

$this->db->select(["Orders.OrderID", "Orders.OrderDate", "Customers.CustomerName"])
         ->from("Customers, Orders")
         ->where("c.CustomerName = cus_name")
         ->and("Customers.CustomerID = Orders.CustomerID")
         ->x();

$sel = $this->db->parameter("cus_name","Around the Horn");
$sel = $this->db->fetch();

//$sel holds the object.

join

A JOIN clause is used to combine rows from two or more tables, based on a related column between them.

The INNER JOIN keyword selects records that have matching values in both tables.

SELECT Orders.OrderID, Customers.CustomerName, Orders.OrderDate FROM Orders INNER JOIN Customers ON Orders.CustomerID=Customers.CustomerID;

<?php

/* SELECT Orders.OrderID, Customers.CustomerName, Orders.OrderDate
FROM Orders INNER JOIN Customers ON Orders.CustomerID=Customers.CustomerID; */

$this->db->select(["Orders.OrderID", "Customers.CustomerName", "Orders.OrderDate"])
         ->from("Orders")
         ->join("Customers","Orders.CustomerID=Customers.CustomerID")
         ->x();

$sel = $this->db->fetch();

//$sel holds the object.

left join

The LEFT JOIN keyword returns all records from the left table (table1), and the matched records from the right table (table2). The result is NULL from the right side, if there is no match.

SELECT Customers.CustomerName, Orders.OrderID FROM Customers LEFT JOIN Orders ON Customers.CustomerID = Orders.CustomerID ORDER BY Customers.CustomerName;

<?php

/* SELECT Customers.CustomerName, Orders.OrderID
FROM Customers LEFT JOIN Orders ON Customers.CustomerID = Orders.CustomerID
ORDER BY Customers.CustomerName; */

$this->db->select(["Customers.CustomerName", "Orders.OrderID"])
         ->from("Customers")
         ->join("Orders","Customers.CustomerID = Orders.CustomerID", "left")
         ->orderBy('Customers.CustomerName')
         ->x();

$sel = $this->db->fetch();

//$sel holds the object.

right join

The RIGHT JOIN keyword returns all records from the right table (table2), and the matched records from the left table (table1). The result is NULL from the left side, when there is no match.

SELECT Orders.OrderID, Employees.LastName, Employees.FirstName FROM Orders RIGHT JOIN Employees ON Orders.EmployeeID = Employees.EmployeeID ORDER BY Orders.OrderID;

<?php

/* SELECT Orders.OrderID, Employees.LastName, Employees.FirstName
FROM Orders
RIGHT JOIN Employees ON Orders.EmployeeID = Employees.EmployeeID
ORDER BY Orders.OrderID; */

$this->db->select(["Orders.OrderID", "Employees.LastName", "Employees.FirstName"])
         ->from("Orders")
         ->join("Employees","Orders.EmployeeID = Employees.EmployeeID", "right")
         ->orderBy('Orders.OrderID')
         ->x();

$sel = $this->db->fetch();

//$sel holds the object.

full outer

The FULL OUTER JOIN keyword return all records when there is a match in either left (table1) or right (table2) table records.

Note: FULL OUTER JOIN can potentially return very large result-sets!

SELECT Customers.CustomerName, Orders.OrderID FROM Customers FULL OUTER JOIN Orders ON Customers.CustomerID=Orders.CustomerID ORDER BY Customers.CustomerName;

<?php

/* SELECT Customers.CustomerName, Orders.OrderID
FROM Customers
FULL OUTER JOIN Orders ON Customers.CustomerID=Orders.CustomerID
ORDER BY Customers.CustomerName; */

$this->db->select(["Customers.CustomerName", "Orders.OrderID"])
         ->from("Customers")
         ->join("Orders","Customers.CustomerID=Orders.CustomerID", "full outer")
         ->orderBy('Customers.CustomerName')
         ->x();

$sel = $this->db->fetch();

//$sel holds the object.

self join

A self JOIN is a regular join, but the table is joined with itself.

SELECT A.CustomerName AS CustomerName1, B.CustomerName AS CustomerName2, A.City FROM Customers A, Customers B WHERE A.CustomerID <> B.CustomerID AND A.City = B.City ORDER BY A.City;

<?php

/* SELECT A.CustomerName AS CustomerName1, B.CustomerName AS CustomerName2, A.City
FROM Customers A, Customers B
WHERE A.CustomerID <> B.CustomerID
AND A.City = B.City
ORDER BY A.City; */

$this->db->select(["A.CustomerName AS CustomerName1",
                   "B.CustomerName AS CustomerName2",
                   "A.City"])
         ->from("Customers A, Customers B")
         ->where("A.CustomerID <> B.CustomerID")
         ->and('A.City = B.City')
         ->orderBy("A.City");
         ->x();

$sel = $this->db->fetch();

//$sel holds the object.

union

The UNION operator is used to combine the result-set of two or more SELECT statements.

SELECT City FROM Customers UNION SELECT City FROM Suppliers ORDER BY City;

<?php

/* SELECT City FROM Customers
UNION
SELECT City FROM Suppliers
ORDER BY City;*/

$this->db->select(["City"])->from("Customers")
         ->union()
         ->select(["City"])->from("Suppliers")
         ->orderBy("City")-x();

$sel = $this->db->fetch();

//$sel holds the object.

union all

SELECT City FROM Customers UNION ALL SELECT City FROM Suppliers ORDER BY City

<?php

/* SELECT City FROM Customers
UNION ALL
SELECT City FROM Suppliers
ORDER BY City*/

$this->db->select(["City"])->from("Customers")
         ->union("all")
         ->select(["City"])->from("Suppliers")
         ->orderBy("City")-x();

$sel = $this->db->fetch();

//$sel holds the object.

union all where

SELECT City, Country FROM Customers WHERE Country='Germany' UNION ALL SELECT City, Country FROM Suppliers WHERE Country='Germany' ORDER BY City;

<?php

/* SELECT City, Country FROM Customers
WHERE Country='Germany'
UNION ALL
SELECT City, Country FROM Suppliers
WHERE Country='Germany'
ORDER BY City;*/

$this->db->select(["City","Country"])->from("Customers")
         ->where("Country = country");
         ->union("all")
         ->select(["City","Country"])->from("Suppliers")
         ->where("Country = country");
         ->orderBy("City")->x();

$sel = $this->db->parameter("country", "Germany");
$sel = $this->db->fetch();

//$sel holds the object.

SELECT City, Country FROM Customers WHERE Country='Germany' UNION SELECT City, Country FROM Suppliers WHERE Country='Germany' ORDER BY City;

<?php

/* SELECT City, Country FROM Customers
WHERE Country='Germany'
UNION
SELECT City, Country FROM Suppliers
WHERE Country='Germany'
ORDER BY City;*/

$this->db->select(["City","Country"])->from("Customers")
         ->where("Country = country");
         ->union()
         ->select(["City","Country"])->from("Suppliers")
         ->where("Country = country");
         ->orderBy("City")->x();

$sel = $this->db->parameter("country", "Germany");
$sel = $this->db->fetch();

//$sel holds the object.

SELECT 'Customer' As Type, ContactName, City, Country FROM Customers UNION SELECT 'Supplier', ContactName, City, Country FROM Suppliers;

<?php

/* SELECT 'Customer' As Type, ContactName, City, Country
FROM Customers
UNION
SELECT 'Supplier', ContactName, City, Country
FROM Suppliers;*/

$this->db->select(["'Customer' As Type, ContactName, City, Country"])
         ->from("Customers")
         ->union()
         ->select(["'Supplier', ContactName, City, Country"])
         ->from("Suppliers")
         ->x();

$sel = $this->db->fetch();

//$sel holds the object.

group by

The GROUP BY statement is often used with aggregate functions

SELECT COUNT(CustomerID), Country FROM Customers GROUP BY Country;

<?php

/* SELECT COUNT(CustomerID), Country
FROM Customers
GROUP BY Country;*/

$this->db->select(["COUNT(CustomerID), Country"])
         ->from("Customers")
         ->groupBy("Country")
         ->x();

$sel = $this->db->fetch();

//$sel holds the object.

SELECT COUNT(CustomerID), Country FROM Customers GROUP BY Country ORDER BY COUNT(CustomerID) DESC;

<?php

/* SELECT COUNT(CustomerID), Country
FROM Customers
GROUP BY Country
ORDER BY COUNT(CustomerID) DESC;*/

$this->db->select(["COUNT(CustomerID), Country"])
         ->from("Customers")
         ->groupBy("Country")
         ->orderBy("COUNT(CustomerID)","desc")
         ->x();

$sel = $this->db->fetch();

//$sel holds the object.

SELECT Shippers.ShipperName, COUNT(Orders.OrderID) AS NumberOfOrders FROM Orders LEFT JOIN Shippers ON Orders.ShipperID = Shippers.ShipperID GROUP BY ShipperName;

<?php

/* SELECT Shippers.ShipperName, COUNT(Orders.OrderID) AS NumberOfOrders FROM Orders
LEFT JOIN Shippers ON Orders.ShipperID = Shippers.ShipperID
GROUP BY ShipperName;*/

$this->db->select(["Shippers.ShipperName, COUNT(Orders.OrderID) AS NumberOfOrders"])
         ->from("Orders")
         ->join("Shippers","Orders.ShipperID = Shippers.ShipperID", "left")
         ->groupBy("ShipperName")
         ->x();

$sel = $this->db->fetch();

//$sel holds the object.

having

The HAVING clause was added to SQL because the WHERE keyword could not be used with aggregate functions.

SELECT COUNT(CustomerID), Country FROM Customers GROUP BY Country HAVING COUNT(CustomerID) > 5;

<?php

/* SELECT COUNT(CustomerID), Country
FROM Customers
GROUP BY Country
HAVING COUNT(CustomerID) > 5;*/

$this->db->select(["COUNT(CustomerID), Country"])
         ->from("Customers")
         ->groupBy("ShipperName")
         ->having("COUNT(CustomerID) > c_cus_id")
         ->x();

$sel = $this->db->parameter("c_cus_id", 5);
$sel = $this->db->fetch();

//$sel holds the object.

SELECT COUNT(CustomerID), Country FROM Customers GROUP BY Country HAVING COUNT(CustomerID) > 5 ORDER BY COUNT(CustomerID) DESC;

<?php

/* SELECT COUNT(CustomerID), Country
FROM Customers
GROUP BY Country
HAVING COUNT(CustomerID) > 5
ORDER BY COUNT(CustomerID) DESC;*/

$this->db->select(["COUNT(CustomerID), Country"])
         ->from("Customers")
         ->groupBy("ShipperName")
         ->having("COUNT(CustomerID) > c_cus_id")
         ->orderBy("COUNT(CustomerID)", "desc")
         ->x();

$sel = $this->db->parameter("c_cus_id", 5);
$sel = $this->db->fetch();

//$sel holds the object.

SELECT Employees.LastName, COUNT(Orders.OrderID) AS NumberOfOrders FROM Orders INNER JOIN Employees ON Orders.EmployeeID = Employees.EmployeeID GROUP BY LastName HAVING COUNT(Orders.OrderID) > 10;

<?php

/* SELECT Employees.LastName, COUNT(Orders.OrderID) AS NumberOfOrders
FROM Orders
INNER JOIN Employees ON Orders.EmployeeID = Employees.EmployeeID
GROUP BY LastName
HAVING COUNT(Orders.OrderID) > 10; */

$this->db->select(["Employees.LastName, COUNT(Orders.OrderID) AS NumberOfOrders"])
         ->from("Orders")
         ->join("Employees","Orders.EmployeeID = Employees.EmployeeID")
         ->groupBy("LastName")
         ->having("Orders.OrderID > c_order_id")
         ->x();

$sel = $this->db->parameter("c_order_id", 5);
$sel = $this->db->fetch();

//$sel holds the object.

SELECT Employees.LastName, COUNT(Orders.OrderID) AS NumberOfOrders FROM Orders INNER JOIN Employees ON Orders.EmployeeID = Employees.EmployeeID WHERE LastName = 'Davolio' OR LastName = 'Fuller' GROUP BY LastName HAVING COUNT(Orders.OrderID) > 25;

<?php

/* SELECT Employees.LastName, COUNT(Orders.OrderID) AS NumberOfOrders
FROM Orders
INNER JOIN Employees ON Orders.EmployeeID = Employees.EmployeeID
WHERE LastName = 'Davolio' OR LastName = 'Fuller'
GROUP BY LastName
HAVING COUNT(Orders.OrderID) > 25; */

$this->db->select(["Employees.LastName, COUNT(Orders.OrderID) AS NumberOfOrders"])
         ->from("Orders")
         ->join("Employees","Orders.EmployeeID = Employees.EmployeeID")
         ->where("LastName = last_name1")->or("LastName = last_name2")
         ->groupBy("LastName")
         ->having("Orders.OrderID > c_order_id")
         ->x();
$sel = $this->db->parameter("last_name1", 'Davolio');
$sel = $this->db->parameter("last_name2", 'Fuller');
$sel = $this->db->parameter("c_order_id", 5);
$sel = $this->db->fetch();

//$sel holds the object.

insert

The INSERT INTO statement is used to insert new records in a table.

INSERT INTO Customers (CustomerName, ContactName, Address, City, PostalCode, Country) VALUES ('Cardinal', 'Tom B. Erichsen', 'Skagen 21', 'Stavanger', '4006', 'Norway');

  <?php

  /*INSERT INTO Customers (CustomerName, ContactName, Address, City, PostalCode, Country)
  VALUES ('Cardinal', 'Tom B. Erichsen', 'Skagen 21', 'Stavanger', '4006', 'Norway'); */

  $this->db->insert("Customers")
           ->values(["CustomerName", "ContactName", "Address", "City", "PostalCode", "Country"])
           ->x();

  $this->db->parameter("CustomerName",'Cardinal');
  $this->db->parameter("ContactName",'Tom B. Erichsen');
  $this->db->parameter("Address",'Skagen 21');
  $this->db->parameter("City",'Stavanger');
  $this->db->parameter("PostalCode",'4006');
  $this->db->parameter("Country",'Norway');

  $ins = $this->db->fetch();

  //$sel holds the last inserted ID.

update

The UPDATE statement is used to modify the existing records in a table.

UPDATE Customers SET ContactName = 'Alfred Schmidt', City= 'Frankfurt' WHERE CustomerID = 1;

   <?php

   /* UPDATE Customers SET ContactName = 'Alfred Schmidt', City= 'Frankfurt'
    WHERE CustomerID = 1; */

   $this->db->update("Customers")
            ->set(["ContactName", "City"])
            ->where("CustomerID = id")
            ->x();

   $this->db->parameter("ContactName",'Alfred Schmidt');
   $this->db->parameter("City",'Frankfurt');
   $this->db->parameter("id",1);

   $upd = $this->db->fetch();

   //$upd hold the boolean - true for updated, and false/null for failed.

delete

The DELETE statement is used to delete existing records in a table.

DELETE FROM Customers WHERE CustomerName='Alfreds Futterkiste';

  <?php

  /* DELETE FROM Customers WHERE CustomerName='Alfreds Futterkiste'; */

  $this->db->delete("Customers")
           ->where("CustomerName = name")
           ->x();

  $this->db->parameter("name",'Alfreds Futterkiste');

  $this->db->fetch();

View & Functions

title

variable holds the title of the page coming from the controller.

  <?php

  echo $this->title;

include

DRY technique to maintain page templates.

  <?php

  $this->include($template_page);

css

css(string, string, array)

include page css

@parameter: string $namespace (@Mandatory)

@parameter: string $path (@Mandatory)

@parameter: array $options (@optional)

Example: ["type" => "text/css"].

  <?php

  $this->css($namespace,$path,$options);

js

js(string, string, array)

include page javascript

@parameter: string $namespace (@Mandatory)

@parameter: string $path (@Mandatory)

@parameter: array $options (@optional)

Example: ["type" => "javascript"].

  <?php

  $this->js($namespace,$path,$options);

img

img(string, string, array)

include page images

@parameter: string $namespace (@Mandatory)

@parameter: string $path (@Mandatory)

@parameter: array $options (@optional)

Example: ["alt" => "myImage"].

  <?php

  $this->img($namespace,$path,$options);

icon

icon(string, string, array)

include page icon

@parameter: string $namespace (@Mandatory)

@parameter: string $path (@Mandatory)

@parameter: array $options (@optional)

Example: ["alt" => "myImage"].

  <?php

  $this->icon($namespace,$path,$options);

get

get(string)

Gets the variable name.

@parameter: String $var_name (Mandatory)

@return: set value from the controller.

<?php

$var = $this->get($name);

meta

meta(array)

@parameter: array $meta.

Sets the Meta information.

<?php

$this->meta($meta);

//Snippet Example
$this->meta([ "http-equiv" => "X-UA-Compatible",
             "content" => "IE=9" ]);

cdn

cdn(string, string, array)

set the content delivery network.

@parameter: string $content_type (@Mandatory)

usually set to js or css.

@parameter: string $path (@Mandatory)

@parameter: string $opt (@Optional)

<?php

this->cdn($content_type, $path, $opt);

internal page link.

@parameter: string $link (@Default: Null)

null value will point to the base link of the portal set in the config file.

<?php

echo this->link($link);

viewport

viewport(string)

Set header viewport attribute.

@paramter: $content (@Default: 'width=device-width, initial-scale=1');

<?php

echo this->viewport($content);

charset

charset(string)

Set header viewport attribute.

@paramter: $content (@Default: 'utf-8');

<?php

echo this->charset($content);

description

description(string)

Set description attribute.

@paramter: $description (@Mandatory);

<?php

echo this->description($description);

Library Functions

config

get XML config values.

namespace: core\lib\utilities

<?php

$d = core\lib\utilities\Config::get('database_credits/database');

translation

internationalisation API from Google.

@parameter string $source: source language.

@parameter string $target: target language.

@parameter string $text: language text.

@return: string: target language text.

namespace: Statickidz

<?php

$d = Statickidz\GoogleTranslate::requestTranslation($source, $target, $text);

Sanitizr

namespace: core\lib\utilities

Remove magic quotes.

<?php

$d = core\lib\utilities\Sanitizr::stripSlashesDeep($value);

Unregister globals

<?php

$d = core\lib\utilities\Sanitizr::unregisterGlobals();

Clean buffer.

<?php

$d = core\lib\utilities\Sanitizr::cleanBuffer();

Session

namespace: none;

initialise Session

<?php

$d = \Session::init();

Session set

<?php

$d = \Session::set($key, $value);

Session set

<?php

$d = \Session::get($key);

check Session exist.

@return: boolean

<?php

$d = \Session::exists($key);

Session destroy.

<?php

$d = \Session::destroy();

Session delete.

<?php

$d = \Session::delete(string $key);

Session flash.

<?php

$d = \Session::flash(string $key, string $string = '')

Timestamp

namespace: core\lib\utilities

<?php

$d = core\lib\utilities\Timestamp::setTime($format = "Y-m-d H:i:s");

Token

namespace: core\lib\utilities

initialise token

initialise the token value.

<?php

$d = core\lib\utilities\Token::init();

generate token

sets a token in session.

<?php

$d = core\lib\utilities\Token::generate();

delete token

deletes the token in session.

<?php

$d = core\lib\utilities\Token::delete();

Binary Functions

Array

array_clean(array $arr)

Removes all the null values in array and re-index the keys.

<?php

$d = array_clean($arr);

array_sort(array $array, string $opt = null, string $by = null)

Sort an array.

@permitted/valid values:

string $opt: ascending, descending.

string $by: key;

<?php

$d = array_sort($array,$opt,$by);

isAssoc(array $arr)

check if an array is associative.

<?php

$d = isAssoc($arr);

ar_find(array $array, string $where, string $value)

search an array by key and condition.

<?php

$d = ar_find($array, $where, $value);

ar_intersect(array $array1, array $array2)

intersect an array.

<?php

$d = ar_intersect($array1, $array2);

ar_difference(array $array1, array $array2)

find the array difference.

<?php

$d = ar_difference($array1, $array2);

ar_unique(array $array1, array $array2)

find the array unique values from 2 different arrays.

<?php

$d = ar_unique($array1, $array2);

array_concatanate(array $arr, string $using)

concatanate all array elements using $using value.

<?php

$d = array_concatanate($arr, $using);

Authorization

auth_object_for_user(sting $obj, string $key = null);

get the authorisation objects for users.

@permitted/value $key: range,activity,object,name

<?php

$d = auth_object_for_user($obj, $key);

Country API

getAllCountries()

get all countries.

<?php

$d = getAllCountries();

getCountryByName($name,$fullname = false)

get country by name.

<?php

$d = getCountryByName($name,$fullname);

getCountryByCode($code)

get country by code.

<?php

$d = getCountryByCode($code);

getCurrencyByCode($currency)

get currency by code.

<?php

$d = getCurrencyByCode($currency);

getLanguageByCode($language)

get language by code.

<?php

$d = getLanguageByCode($language);

getDetailByCapital($capital)

get details by country capital.

<?php

$d = getDetailByCapital($capital);

getDetailByCallCode($callCode)

get details by country call code.

<?php

$d = getDetailByCallCode($callCode);

getDetailByRegion($region)

get details by country region.

<?php

$d = getDetailByRegion($region);

regionalBloc($block)

get details by country region block.

<?php

$d = regionalBloc($block);

getPlacesDetails(Array $details)

Example: ["name","capital","currencies"]

get details by country multiple values.

<?php

$d = getPlacesDetails($details);

Database

Get database instance.

pdo()

<?php

$db = pdo();

view_clear(string $view_name)

Drops an existing view.

<?php

view_clear($view_name);

dbcount(array $arr)

counts the db query results.

<?php

dbcount($arr);

Date

sytime($format = "h:i:sa")

get system current time.

<?php

$t = sytime($format);

sydate($format = "Y-m-d")

get system current date.

<?php

$t = sydate($format);

isDate($month, $day, $year)

check input is a valid date.

<?php

$t = isDate($month, $day, $year);

current_time()

differ from other function by time formatting.

<?php

$t = current_time();

current_date()

differ from other function by date formatting.

<?php

$t = current_date();

now()

differ from other function by date-time formatting.

<?php

$t = now();

get_localtime()

get local time.

<?php

$t = get_localtime();

word_month(int $number)

get month in words by month number.

<?php

$t = word_month($number);

add_to_date($date, $opt = array(), $format = "Y-m-d")

addition to date.

@permitted: $opt: day,month,year,hours,minutes,seconds

<?php

$t = add_to_date($date, $opt, $format);

substract_to_date($date, $opt = array(), $format = "Y-m-d")

subtraction from date.

@permitted: $opt: day,month,year,hours,minutes,seconds

<?php

$t = substract_to_date($date, $opt, $format);

change_date_format($input_date, $rformat, $add_string)

change date format

<?php

$t = change_date_format($input_date, $rformat, $add_string);

format_date($idate, $format = "Y/m/d H:i:s")

date formatting.

<?php

$t = format_date($idate, $format);

date_difference($setdate1, $setdate2)

date difference, differ from other function by date-time formatting.

<?php

$t = date_difference($setdate1, $setdate2);

date_explode($date)

explode date into array.

<?php

$t = date_explode($date);

db_date_function($date, $seprator = ' ')

database date function for formatting.

<?php

$t = db_date_function($date, $seprator);

db_first_last_day($query_date = '')

get the first and last day of the query date.

<?php

$t = db_first_last_day($query_date);

db_today()

get todays date-time detail.

<?php

$t = db_today();

db_add_sub_date($number)

database function for date add/substrate.

<?php

$t = db_add_sub_date($number);

db_time_diff($date1, $date2)

database function for date difference.

<?php

$t = db_time_diff($date1, $date2);

timeFunction($string, $format = '')

database function time function.

<?php

$t = timeFunction($string, $format);

Debug

debug($var, string $value = 'backtrace')

Application debugger

<?php

debug($var,$value);

declared_classes()

get all declared classes.

<?php

declared_classes();

Logs

writeDBLog($e, $query = null)

write exception log.

<?php

writeDBLog($e, $query);

applicationLog($msg)

write application log file.

<?php

applicationLog($msg);

deleteLog($query, $record)

write delete log file.

<?php

deleteLog($query, $record);

stackTrace()

get stacktrace.

<?php

stackTrace();

File

getFileStructure($location, $resource = false);

<?php

getFileStructure($location, $resource);

readFileStructure($location, $reverse = false);

<?php

readFileStructure($location, $reverse = false);

list_directory($location);

<?php

list_directory($location);

list_files($location);

<?php

list_files($location);

read_file($location);

<?php

read_file($location);

read_file_content($location);

<?php

read_file_content($location);

destroyDir($dir, $virtual = false);

<?php

destroyDir($dir, $virtual);

Currency formatting

currency_format($amount, $decimals = null, $decimalpoint = null, $separator = null)

<?php

currency_format($amount, $decimals, $decimalpoint, $separator)

Hash

hash_encrypt(string $data)

<?php

hash_encrypt($data)

hash_token(string $type = 'md5')

<?php

$t = hash_token($type);

sha_token($str, $opt = FALSE)

<?php

$t = sha_token($str, $opt);

decrypt($string, $key)

<?php

$t = decrypt($string, $key);

encrypt($string, $key)

<?php

$t = encrypt($string, $key);

url($path = null)

<?php

$t = url($path);

dbase()

<?php

$t = dbase();

external_url_exist($url)

<?php

$t = external_url_exist($url);

jsonp_is_valid_callback($subject)

<?php

$t = jsonp_is_valid_callback($subject);

action_check($action_method)

<?php

$t = action_check($action_method);

getBaseUrl()

<?php

$t = getBaseUrl();

location

write_log($log_type, $error_desc, $filename = null)

@parameter: log_type: db, audit, application.

<?php

write_log($log_type, $error_desc, $filename);

loc_file_log($log_type, $filename = null)

@parameter: $log_type: db, audit, application.

<?php

loc_file_log($log_type, $filename);

loc_file_import($folder, $file)

@parameter: $folder: db, audit, application.

<?php

loc_file_import(($folder, $file);

Public folder

path($string = null,$section = null)

@parameter: $section: project.

<?php

path($string,$section);

publicFolder($myFolder,$section = null)

@parameter: $section: project.

<?php

publicFolder($myFolder,$section);

folderAccess($path,$section = null)

@parameter: $section: project.

<?php

folderAccess($path,$section);

checkFilePermission($file)

<?php

checkFilePermission($file);

changeFolderPermission($path, $permission = "0755")

<?php

changeFolderPermission($path, $permission);

makePublicWritable($path)

<?php

makePublicWritable($path);

Redirection

redirect(string $location)

<?php

redirect($location);

request_page(string $redirection = "")

<?php

request_page($redirection);

Security

filter($data);

<?php

filter($data);

readable_random_string($length = 6)

<?php

readable_random_string($length);

generate_rand($length)

<?php

generate_rand($length);

encode_email($email='info@domain.com',

$linkText='Contact Us', $attrs ='class="emailencoder"' )

<?php

encode_email($email,$linkText,$attrs);

is_valid_email($email, $test_mx = false)

<?php

is_valid_email($email, $test_mx);

String

get_string_between($string, $start, $end)

<?php

get_string_between($string, $start, $end);

html_statement($str)

<?php

html_statement($str);

local_information($string)

<?php

local_information($string);

replace_occurrence_of($string, $with)

<?php

replace_occurrence_of($string, $with);

get_by_position($string, $start_pos, $end_pos = null)

<?php

get_by_position($string, $start_pos, $end_pos);

get_by_position_after($string, $start_pos)

<?php

get_by_position_after($string, $start_pos);

get_by_position_before($string, $end_pos)

<?php

get_by_position_before($string, $end_pos)

uppercase($string)

<?php

uppercase($string)

lowercase($string)

<?php

lowercase($string)

prettyWords($words)

Uppercase the first letter and lower case the rest.

<?php

prettyWords($words)

findWords($string,$word,$before=0,$after=0,$maxFoundCount=1)

<?php

findWords($string,$word,$before,$after,$maxFoundCount)

str_clean($string)

removes unwanted symbols and strings.

<?php

str_clean($string)

get_decorated_diff(string $old, string $new)

Colorify the words.

<?php

$str_arr = get_decorated_diff($old, $new);

System

DNS()

get DNS info.

<?php

$i = DNS();

isLocalhost()

check if it is a localhost.

<?php

$i = isLocalhost();

getClientIP()

get client IP Address.

<?php

$i = getClientIP();

isAjax()

check if request is ajax.

<?php

$i = isAjax();

getServerUrl()

get server url.

<?php

$i = getServerUrl();

get_uid();

get system unique id.

<?php

$i = get_uid();

get_pid();

get system process id.

<?php

$i = get_pid();

UniqueMachineID($salt = "");

get machine unique id / Mac id.

<?php

$i = UniqueMachineID($salt);

homepath()

<?php

$i = homepath();

homedrive()

<?php

$i = homedrive();

username()

<?php

$i = username();

get_mac_address()

<?php

$i = get_mac_address();

getRealIpAddr()

get real IP Address.

<?php

$i = getRealIpAddr();

force_download($file)

<?php

$i = force_download($file);

Utilities

condense($str);

 <?php

 $i = condense($str);

concatenate($str = '')

<?php

$i = concatenate($str);

echo_json($data)

<?php

$i = echo_json($data);

json_api($data,$extra = "")

<?php

$i = json_api($data,$extra);

is_initial($value,$key = null)

check if the variable is initial.

<?php

$i = is_initial($value,$key);

create_slug($string)

<?php

$i = create_slug($string);

getClassFile($class)

<?php

$i = getClassFile($class);

removeSpaces(String $string)

<?php

$i = removeSpaces($string);

removeWhiteSpaces(String $string)

<?php

$i = removeWhiteSpaces($string);

createObject()

<?php

$i = createObject();

Configuration Index

Basic Configurations

Tag Description
PROJECT Description of you project.
BASE The base link of your project on server.
ENVIRONMENT It takes up the values - [development, quality, production]
DATASOURCE Specifies the name of your Database. (Example - MySql).
PORT Specifies the port of your Database (Default Example - 3306).
DATABASE Specifies the database of your Database.
LOGIN Specifies the login user of your Database.
PASSWORD Specifies the password of your Database.
SECURITY_SALT Specifies the security hashing Key for your password. This will be used for your password hashing when you create the login system of your application.

phpMailer

Tag Description
MAIL_HOST Set the SMTP Host.
MAIL_USER Set the SMTP User. Usually the sender Address.
MAIL_PASSWORD User Password.
MAIL_SMTP_SECURE SMTP Secure Layer Protocol.
MAIL_PORT Sets the mail port.
MAIL_SET_FROM Sets the Email Sent from.
MAIL_SET_FROM_TYPE Set the Sender's Mail type
MAIL_SMTP_AUTH SMTP Authorisation.
TEMPLATE_FOLDER Email Template Folder.

The extensive documentation will be found here

Integrations

Vendor Integrations

The Application was Pre-Configures with PHP-Mailer for messageing purpose. Be sure to visit them for their documentations when required.