BaseClass
provides powerful methods to allow your custom classes to use a database table. To start
using the benefits, your class must extends the BaseClass
:
class <Your_Class> extends BaseClass {
...
}
Then, all you need to do is to declare some pre-defined variables:
protected $attribute1
protected $attribute2
protected $attribute3
protected $default_values = [
"attribute1" => "default_value",
"attribute2" => "default_value",
...
]
const TABLENAME = "tablename"
In the class constructor, you have to invoke the init
method of the BaseClass
and, optionally, it can accept an $id
parameter to automatically load the instance with that ID:
public function __construct($id = NULL) {
parent::init($id);
}
Optionally, you can declare some variables that are not linked with the database table. This kind of variables are excluded from every
operation that involves database (insert and update).
For that, you can declare you custom variable
and then the $custom_excluded
instance variable that must contains all of this attributes name.
For example:
protected $myVar; // variable not in the database table
protected $custom_excluded = ["myVar"];
fill($array)
clearAndFill($array)
load($id)
exist($id)
save()
save($id)
)delete()
lockTable()
unlockTable()
methodunlockTable()
BaseList
provides powerful methods to allow your custom classes to use a database table as List. To start
using the benefits, your class must extends the BaseList
:
class <Your_Class> extends BaseList {
...
}
To use BaseList you need to first declare the BaseClass
table into a Constant
CONST BASE_CLASS = ::class;
Than initialize the constructor method of the BaseList class
public function __construct(){
parent::init()
}
view($fields,$orderColumn,$orderType,$numitem,$currentPage).
view($fields, $orderColumn, $orderType, $numitem, $currentPage);
$fields is a Array composed by three option: columnName, operator and the word to search.
$orderColumn contain the name of column to order by.
$orderType can be "ASC" or "DESC" to get data Ascended or Descended.
$numitem container the Limit element of how much item to view.
$currentPage contain the current page number according to the number of item to view.
loadAll()
truncate()
getIterator()
getItemsArray()
size()
isEmpty()
jsonSerialize()
add($element)
get($key)
remove($key,$shift)
clear()
fill