UserModel.php
788 Bytes
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
<?php
require_once __DIR__.'/../app/data.php';
class UserModel
{
protected $id;
protected $data = array();
protected $saved = false;
public function getName()
{
return $this->data['name'];
}
function setName($name)
{
$this->data['name'] = 'Mr. '.$name;
}
function getId()
{
return $this->id;
}
function get($param)
{
if (!isset($this->data[$param])) throw new \Exception('Key does not exist!');
return $this->data[$param];
}
function set($param, $value)
{
$this->data[$param] = $value;
}
function save()
{
if (!$this->id) $this->id = uniqid();
data::set($this->id, $this->data);
$this->saved = true;
return true;
}
}