1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Rougin\Credo; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Codeigniter Model |
7
|
|
|
* |
8
|
|
|
* @package Credo |
9
|
|
|
* @author Rougin Royce Gutib <[email protected]> |
10
|
|
|
*/ |
11
|
|
|
class CodeigniterModel extends \CI_Model |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @var \Rougin\Credo\Credo |
15
|
|
|
*/ |
16
|
|
|
protected $credo; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @var \Doctrine\ORM\EntityRepository |
20
|
|
|
*/ |
21
|
|
|
protected $repository; |
22
|
|
|
|
23
|
3 |
|
public function __construct() |
24
|
|
|
{ |
25
|
3 |
|
parent::__construct(); |
26
|
|
|
|
27
|
3 |
|
$this->credo = new Credo($this->db); |
|
|
|
|
28
|
3 |
|
$this->repository = $this->credo->getRepository(get_class($this)); |
|
|
|
|
29
|
3 |
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Returns all of the models from the database. |
33
|
|
|
* |
34
|
|
|
* @return array |
35
|
|
|
*/ |
36
|
3 |
|
public function all() |
37
|
|
|
{ |
38
|
3 |
|
return $this->find_by([]); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Deletes the specified ID of the model from the database. |
43
|
|
|
* |
44
|
|
|
* @param integer $id |
45
|
|
|
* @return void |
46
|
|
|
*/ |
47
|
3 |
|
public function delete($id) |
48
|
3 |
|
{ |
49
|
2 |
|
$item = $this->find($id); |
50
|
|
|
|
51
|
2 |
|
$this->credo->remove($item); |
|
|
|
|
52
|
2 |
|
$this->credo->flush(); |
|
|
|
|
53
|
2 |
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Finds an entity by its primary key / identifier. |
57
|
|
|
* |
58
|
|
|
* @param mixed $id |
59
|
|
|
* @param int|null $lockMode |
60
|
|
|
* @param int|null $lockVersion |
61
|
|
|
* @return object|null |
62
|
|
|
*/ |
63
|
4 |
|
public function find($id, $lockMode = null, $lockVersion = null) |
64
|
|
|
{ |
65
|
4 |
|
return $this->repository->find($id, $lockMode, $lockVersion); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Finds models by a set of criteria. |
70
|
|
|
* |
71
|
|
|
* @param array $criteria |
72
|
|
|
* @param array|null $orderBy |
73
|
|
|
* @param integer|null $limit |
74
|
|
|
* @param integer|null $offset |
75
|
|
|
* @return array |
76
|
|
|
*/ |
77
|
3 |
|
public function find_by(array $criteria, array $orderBy = null, $limit = null, $offset = null) |
78
|
|
|
{ |
79
|
3 |
|
return $this->repository->findBy($criteria, $orderBy, $limit, $offset); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|
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@property
annotation 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.