Repository navigation
Expand file tree
/
Copy pathModel.php
More file actions
91 lines (77 loc) · 2.11 KB
/
Copy pathModel.php
File metadata and controls
91 lines (77 loc) · 2.11 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
namespace LCloss\Sql;
class Model {
const MSG_ERROR = 'MSG_ERROR';
const MSG_SUCCESS = 'MSG_SUCCESS';
private $values = [];
/**
* Magic Function when call <Class>->set<column>(<args>) or <Class>->get<column>(<args>)
*
* @param method name $name
* @param args passed to the method $args
* @return NULL|mixed
*/
public function __call($name, $args)
{
$method = substr($name, 0, 3);
$columnName = substr($name, 3, strlen($name) - 3);
switch ($method)
{
case 'get':
return (isset($this->values[$columnName]) ? $this->values[$columnName] : NULL);
break;
case 'set':
$this->values[$columnName] = $args[0];
break;
}
}
/**
* Set all data to the Model
*
* @param array of columns $data
*/
public function setData($data)
{
foreach ($data as $key => $value)
{
$this->{"set" . $key}($value);
}
}
/**
* Get all values from the Model
*
* @return array
*/
public function getValues()
{
return $this->values;
}
public static function clearMsgError()
{
$_SESSION[Model::MSG_ERROR] = NULL;
}
public static function clearMsgSuccess()
{
$_SESSION[Model::MSG_SUCCESS] = NULL;
}
public static function setMsgError($msg)
{
$_SESSION[Model::MSG_ERROR] = $msg;
}
public static function setMsgSuccess($msg)
{
$_SESSION[Model::MSG_SUCCESS] = $msg;
}
public static function getMsgError()
{
$msg = ( isset($_SESSION[Model::MSG_ERROR]) && $_SESSION[Model::MSG_ERROR] != '' ? $_SESSION[Model::MSG_ERROR] : '' );
self::clearMsgError();
return $msg;
}
public static function getMsgSuccess()
{
$msg = ( isset($_SESSION[Model::MSG_SUCCESS]) && $_SESSION[Model::MSG_SUCCESS] != '' ? $_SESSION[Model::MSG_SUCCESS] : '' );
self::clearMsgSuccess();
return $msg;
}
}