01.
class
Model_Users
extends
Model_Table{
02.
public
$table
=
'user'
;
03.
function
init() {
04.
parent::init();
05.
$this
->addField(
'display_name'
)->caption(
'Display name'
);
06.
$this
->addField(
'email'
);
07.
$this
->addField(
'password'
)->type(
'password'
)->mandatory(
'Enter the password.'
);
08.
$this
->addField(
'birth_date'
)->type(
'date'
);
09.
$this
->addField(
'created'
)->type(
'datetime'
)->defaultValue(
date
(
'Y-m-d H:i:s'
));
10.
$this
->addField(
'status'
)->enum(
array
(
'active'
,
'ban'
,
'disable'
))->mandatory(
'Please select user status.'
)->defaultValue(
'active'
);
11.
$this
->addField(
'is_admin'
)->type(
'boolean'
)->caption(
'Admin'
);
12.
$this
->addField(
'is_editor'
)->type(
'boolean'
)->caption(
'Editor'
);
13.
$this
->addField(
'is_blogger'
)->type(
'boolean'
)->caption(
'Blogger'
);
14.
$this
->addField(
'is_member'
)->type(
'boolean'
)->defaultValue(1)->caption(
'Member'
);
15.
16.
$this
->addHook(
'beforeSave'
,
function
(
$m
){
17.
$m
[
'email'
] = trim(
strtolower
(
$m
[
'email'
]));
18.
});
19.
}
20.
}