NAV Navbar
php

Introduction

Welcome to the Webcore! a PHP Framework.

MVC

Model

Sample Model File

<?php
class user_model extends wc_model {

     public function getClient($client_id) {
          $result = $this->db->setTable('clients')
                              ->setFields(array('client_name', 'address'))
                              ->setWhere("id = '$client_id'")
                              ->setLimit(1)
                              ->getRow();

          return $result;
     }

}
?>

Handles the database connection your application needs.

View

Sample View File

<?php if ($client): ?>
<p>Client Name: <?php echo $client->client_name ?></p>
<p>Address: <?php echo $client->address ?></p>
<?php endif ?>

The presentation layer in your application. They give you powerful tools to create HTML and the other outputs your application needs.

Controller

Sample Controller File

<?php
class controller extends wc_controller {

     public function __construct() {
          parent::__construct();
          $this->client_model = new client_model();
     }

     public function view($client_id) {
          $data['client'] = $this->client_model->getClient($client_id);
          $this->view->load('client', $data);
     }

}
?>

Handle requests and co-ordinate your models and the responses your application creates.

DB

changeDatabase()

String Database Name

<?php
$this->db->changeDatabase('company');
?>

Changes Database Connection.

Function Parameters

Parameter Default Description
database none Database Name

setTable()

String Table Name

<?php
$this->db->setTable('clients');
?>

The above command returns DB Instance

Set Table for Query.

Function Parameters

Parameter Default Description
table none Table Name

setFields()

Array Field Name

<?php
$this->db->setTable('clients')
          ->setFields(array('client_name', 'address'));
?>

OR String Field Name

<?php
$this->db->setTable('clients')
          ->setFields('client_name, address');
?>

The above command returns DB Instance

Set Fields for Query.

Function Parameters

Parameter Default Description
fields none String or Array of Fields

innerJoin()

String Table Name with ON Clause

<?php
$this->db->setTable('clients c')
          ->innerJoin('invoices i ON c.id = i.client_id');
?>

The above command returns DB Instance

Add Inner Join to Query.

Function Parameters

Parameter Default Description
join none Table Join String

leftJoin()

String Table Name with ON Clause

<?php
$this->db->setTable('clients c')
          ->leftJoin('invoices i ON c.id = i.client_id');
?>

The above command returns DB Instance

Add Left Join to Query.

Function Parameters

Parameter Default Description
join none Table Join String

setWhere()

String WHERE Clause

<?php
$this->db->setTable('clients')
          ->setFields(array('client_name', 'address'))
          ->setWhere("client_name = 'BIR'");
?>

The above command returns DB Instance

Set Where for Query.

Function Parameters

Parameter Default Description
where none Where String

setGroupBy()

String GROUP BY Clause

<?php
$this->db->setTable('clients')
          ->setFields(array('client_name', 'address'))
          ->setWhere("client_name = 'BIR'")
          ->setGroupBy('client_type');
?>

The above command returns DB Instance

Set Group By for Query.

Function Parameters

Parameter Default Description
groupby none Group By String

setHaving()

String HAVING Clause

<?php
$this->db->setTable('clients')
          ->setFields(array('client_name', 'address'))
          ->setWhere("client_name = 'BIR'")
          ->setHaving("client_type = 'Partner'");
?>

The above command returns DB Instance

Set Having for Query.

Function Parameters

Parameter Default Description
having none Having String

setOrderBy()

String ORDER BY Clause

<?php
$this->db->setTable('clients')
          ->setFields(array('client_name', 'address'))
          ->setWhere("client_name = 'BIR'")
          ->setOrderBy('client_type');
?>

The above command returns DB Instance

Set Order By for Query.

Function Parameters

Parameter Default Description
orderby none Order By String

setLimit()

Integer / String Number

<?php
$this->db->setTable('clients')
          ->setFields(array('client_name', 'address'))
          ->setWhere("client_name = 'BIR'")
          ->setLimit(10);
?>

The above command returns DB Instance

Set Limit for Query.

Function Parameters

Parameter Default Description
limit none Number

setLimitOffset()

Integer / String Number

<?php
$this->db->setTable('clients')
          ->setFields(array('client_name', 'address'))
          ->setWhere("client_name = 'BIR'")
          ->setLimit(10)
          ->setLimitOffset(100);
?>

The above command returns DB Instance

Set Limit Offset for Query.

Function Parameters

Parameter Default Description
limit_offset none Number

setValues()

Array of Values with Column Name as Index

<?php
$this->db->setTable('clients')
          ->setValues(array('client_name' => 'BIR', 'address' => 'Makati City'));
?>

OR Array of Array of Values with Column Name as Index for Multiple Row Only Works for INSERT Query

<?php
$this->db->setTable('clients')
          ->setValues(array(
               array('client_name' => 'BIR', 'address' => 'Makati City'),
               array('client_name' => 'NBI', 'address' => 'Pasig City')
          ));
?>

The above command returns DB Instance

Set Values for INSERT / UPDATE Query.

Function Parameters

Parameter Default Description
values none Array Values with Index Field or Array with Array Values

setValuesFromPost()

Array of Column Name as Index with Array Values

<?php
$this->db->setTable('clients')
          ->setValues(array(
               'client_name'  => array('BIR', 'NBI'),
               'address'      => array('Makati City', 'Pasig City')
          ));
?>

The above command returns DB Instance

Set Values for INSERT Query.

Function Parameters

Parameter Default Description
addon true Array with Array Values

buildSelect()

Generate SELECT Query

<?php
$this->db->setTable('clients')
          ->setFields(array('client_name', 'address'))
          ->buildSelect();
?>

->buildSelect(false) will Not Add Company Code to WHERE Clause The above command returns String of SELECT Query

Generate SELECT Query.

Function Parameters

Parameter Default Description
addon true If true, Auto add Company Code to WHERE Clause

buildInsert()

Generate INSERT Query

<?php
$this->db->setTable('clients')
          ->setValues(array('client_name' => 'BIR', 'address' => 'Makati City'))
          ->buildInsert();
?>

->buildInsert(false) will Not Add Company Code to Values The above command returns String of INSERT Query

Generate INSERT Query.

Function Parameters

Parameter Default Description
addon true If true, Auto add Company Code to Values

buildUpdate()

Generate UPDATE Query

<?php
$this->db->setTable('clients')
          ->setFields(array('client_name', 'address'))
          ->buildUpdate();
?>

->buildUpdate(false) will Not Add Company Code to WHERE Clause The above command returns String of UPDATE Query

Generate UPDATE Query.

Function Parameters

Parameter Default Description
addon true If true, Auto add Company Code to WHERE Clause

buildDelete()

Generate DELETE Query

<?php
$this->db->setTable('clients')
          ->setWhere("id = '1'")
          ->buildDelete();
?>

->buildDelete(false) will Not Add Company Code to WHERE Clause The above command returns String of DELETE Query

Generate DELETE Query.

Function Parameters

Parameter Default Description
addon true If true, Auto add Company Code to WHERE Clause

runSelect()

Run SELECT Query

<?php
$this->db->setTable('clients')
          ->setFields(array('client_name', 'address'))
          ->runSelect();
?>

->runSelect(false) will Not Add Company Code to WHERE Clause The above command returns DB Instance See getRow() or getResult()

Run as SELECT Query.

Function Parameters

Parameter Default Description
addon true If true, Auto add Company Code to WHERE Clause

getRow()

Get First Query Result

<?php
$this->db->setTable('clients')
          ->setFields(array('client_name', 'address'))
          ->runSelect()
          ->getRow();
?>

The above command returns First Result as Object

Get First Query Result.

getResult()

Get Query Results

<?php
$this->db->setTable('clients')
          ->setFields(array('client_name', 'address'))
          ->runSelect()
          ->getResult();
?>

The above command returns Results as Array of Object

Get Query Results.

runInsert()

Run INSERT Query

<?php
$this->db->setTable('clients')
          ->setValues(array('client_name' => 'BIR', 'address' => 'Makati City'))
          ->runInsert();
?>

->runInsert(false) will Not Add Company Code to Values The above command returns Boolean

Run as INSERT Query.

Function Parameters

Parameter Default Description
addon true If true, Auto add Company Code to Values

runUpdate()

Run UPDATE Query

<?php
$this->db->setTable('clients')
          ->setFields(array('client_name', 'address'))
          ->runUpdate();
?>

->runUpdate(false) will Not Add Company Code to WHERE Clause The above command returns Boolean

Run as UPDATE Query.

Function Parameters

Parameter Default Description
addon true If true, Auto add Company Code to WHERE Clause

runDelete()

Run DELETE Query

<?php
$this->db->setTable('clients')
          ->setWhere("id = '1'")
          ->runDelete();
?>

->runDelete(false) will Not Add Company Code to WHERE Clause The above command returns Boolean

Run as DELETE Query.

Function Parameters

Parameter Default Description
addon true If true, Auto add Company Code to WHERE Clause

getQuery()

Get Previously Built / Run Query

<?php
$this->db->getQuery();
?>

The above command returns String Query

Get Previously Built / Run Query.

getNumRows()

Get Number of Rows from SELECT Query

<?php
$this->db->getNumRows();
?>

The above command returns Integer Number of Rows

Get Number of Rows from SELECT Query.

getInsertId()

Get ID of Inserted Data

<?php
$this->db->getInsertId();
?>

The above command returns Integer ID

Get ID of Inserted Data.

runPagination()

Run SELECT Query with Pagination

<?php
$this->db->setTable('clients')
          ->setFields(array('client_name', 'address'))
          ->runPagination();
?>

->runPagination(false) will Not Add Company Code to WHERE Clause The above command returns Object of Pagination Data

<?php
// Return Code From runPagination
return (object) array(
     'result'       => $this->getResult(),     // SELECT Query Result
     'result_count' => $this->result_count,    // Number of Results
     'page'         => $this->page,            // Current Page
     'page_limit'   => $this->page_limit,      // Page Count
     'pagination'   => $this->drawPagination() // Pagination HTML Code
);
?>

Run SELECT Query with Pagination.

Function Parameters

Parameter Default Description
addon true If true, Auto add Company Code to WHERE Clause

UI Class

php