-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp_model.php
More file actions
executable file
·58 lines (53 loc) · 1.48 KB
/
Copy pathapp_model.php
File metadata and controls
executable file
·58 lines (53 loc) · 1.48 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
<?php
class AppModel extends Model {
/**
* Define a Error Message for a rule.
* To be used on each model's __construct method
*
* @param string $path Path to the rule defined in array dot notation. "field.rule"
* @param string $message message to assign
* @return void
* @author Joaquin Windmuller
*/
protected function defineErrorMessage($path, $message) {
$this->validate = Set::insert($this->validate, $path . '.message', $message);
}
/**
* Initialize Validation
* Stub. Must be defined by models to create internationalized validation messages
*
* @return void
* @author Joaquin Windmuller
*/
protected function __initializeValidation() {}
/**
* Adds a call to __initializeValidation and calls Model::__construct
*
* @param string $id
* @param string $table
* @param string $ds
* @see Model::__construct
* @author Joaquin Windmuller
*/
function __construct($id = false, $table = null, $ds = null) {
$this->__initializeValidation();
parent::__construct($id, $table, $ds);
}
/**
* Validation rule to check if a field is unique
*
* @param array $data
* @return void
*/
function validateUnique($data) {
$name = array_pop(array_keys($data));
if (!empty($this->id)) {
$conditions = array('NOT' => array($this->primaryKey => $this->id), 'AND' => array($name => $data[$name]));
} else {
$conditions = array($name => $data[$name]);
}
$result = $this->field($this->primaryKey, $conditions);
return $result === false;
}
}
?>