-
Notifications
You must be signed in to change notification settings - Fork 5
/
model.php
56 lines (48 loc) · 1.22 KB
/
model.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
include_once('databases.php');
class Model {
/**
* Contains DB connection or false
* @var bool|DatabaseFactory
*/
private $DB = false;
/**
* Contains instance of Loader class
* @var Loader
*/
private $_l = false;
/**
* private getter for loader
* @return Loader
*/
private function _loader() {
if (!$this->_l) {
$this->_l = new Loader($this);
}
return $this->_l;
}
public function __get($var) {
switch ($var) {
case "DB":
if (!($this->DB)) $this->DB = new DatabaseFactory();
break;
}
return $this->$var;
}
/**
* Load model
* @param string $name Name of the model
* @param string $load_as (optional) Load model as this name
*/
protected function load_model($name, $load_as = false) {
return $this->_loader()->model($name, $load_as);
}
/**
* Load library
* @param string $name Name of the library
* @param string $load_as (optional) Load library as this name
*/
protected function load_library($name, $load_as = false) {
return $this->_loader()->library($name, $load_as);
}
}