|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Rougin\Wildfire; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Codeigniter Model |
|
7
|
|
|
* |
|
8
|
|
|
* @package Wildfire |
|
9
|
|
|
* @author Rougin Royce Gutib <[email protected]> |
|
10
|
|
|
*/ |
|
11
|
|
|
class CodeigniterModel extends \CI_Model |
|
12
|
|
|
{ |
|
13
|
|
|
use Traits\ModelTrait; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @var \Rougin\Wildfire\Wildfire |
|
17
|
|
|
*/ |
|
18
|
|
|
protected $wildfire; |
|
19
|
|
|
|
|
20
|
12 |
|
public function __construct() |
|
21
|
|
|
{ |
|
22
|
12 |
|
parent::__construct(); |
|
23
|
|
|
|
|
24
|
12 |
|
$this->wildfire = new Wildfire($this->db); |
|
|
|
|
|
|
25
|
12 |
|
} |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Returns all of the models from the database. |
|
29
|
|
|
* |
|
30
|
|
|
* @return array |
|
31
|
|
|
*/ |
|
32
|
3 |
|
public function all() |
|
33
|
|
|
{ |
|
34
|
3 |
|
return $this->findBy([]); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Deletes the specified ID of the model from the database. |
|
39
|
|
|
* |
|
40
|
|
|
* @param integer $id |
|
41
|
|
|
* @return void |
|
42
|
|
|
*/ |
|
43
|
|
|
public function delete($id) |
|
44
|
|
|
{ |
|
45
|
|
|
return $this->wildfire->delete($this->getTableName(), $id); |
|
|
|
|
|
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Finds the specified model from the database. |
|
50
|
|
|
* |
|
51
|
|
|
* @param integer $id |
|
52
|
|
|
* @return mixed |
|
53
|
|
|
*/ |
|
54
|
3 |
|
public function find($id) |
|
55
|
|
|
{ |
|
56
|
3 |
|
return $this->wildfire->find($this->getTableName(), $id); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Finds the specified model from the database by the given delimiters. |
|
61
|
|
|
* |
|
62
|
|
|
* @param array $delimiters |
|
63
|
|
|
* @return mixed |
|
64
|
|
|
*/ |
|
65
|
3 |
|
public function findBy(array $delimiters) |
|
66
|
|
|
{ |
|
67
|
3 |
|
$this->db->where($delimiters); |
|
|
|
|
|
|
68
|
|
|
|
|
69
|
3 |
|
return $this->get()->result(); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* Returns all rows from the specified table. |
|
74
|
|
|
* |
|
75
|
|
|
* @return self |
|
76
|
|
|
*/ |
|
77
|
3 |
|
public function get() |
|
78
|
|
|
{ |
|
79
|
3 |
|
return $this->wildfire->get($this->getTableName()); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* Calls methods from this class in underscore case. |
|
84
|
|
|
* |
|
85
|
|
|
* @param string $method |
|
86
|
|
|
* @param mixed $parameters |
|
87
|
|
|
* @return mixed |
|
88
|
|
|
*/ |
|
89
|
|
View Code Duplication |
public function __call($method, $parameters) |
|
|
|
|
|
|
90
|
|
|
{ |
|
91
|
|
|
$method = camelize($method); |
|
92
|
|
|
$result = $this; |
|
93
|
|
|
|
|
94
|
|
|
if (method_exists($this, $method)) { |
|
95
|
|
|
$class = [$this, $method]; |
|
96
|
|
|
|
|
97
|
|
|
$result = call_user_func_array($class, $parameters); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
return $result; |
|
101
|
|
|
} |
|
102
|
|
|
} |
|
103
|
|
|
|
Since your code implements the magic getter
_get, this function will be called for any read access on an undefined variable. You can add the@propertyannotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.