UserModel
extends DbModel
in package
Base Active Record-like model for DB-backed entities.
Subclasses must provide tableName() and tableKeys().
Table of Contents
Constants
- RULE_EMAIL : mixed = 'email'
- RULE_MATCH : mixed = 'match'
- RULE_MAX : mixed = 'max'
- RULE_MIN : mixed = 'min'
- RULE_REQUIRED : mixed = 'required'
- RULE_UNIQUE : mixed = 'unique'
Properties
- $errors : array<string|int, mixed>
Methods
- addError() : mixed
- attributes() : mixed
- attributesTypes() : array<string|int, mixed>
- Returns an array of column names mapped to their respective database data types.
- errorMessage() : mixed
- errorMessages() : mixed
- findOne() : static|false
- Fetch a single record by conditions and map it to the current subclass.
- form() : array<string|int, mixed>
- getDisplayName() : string
- getFirstError() : mixed
- getInputInnerAttribute() : string|false
- getInputInnerAttributes() : string|false
- getInputInnerType() : string|false
- getInputOuterAttribute() : string|false
- getInputOuterAttributes() : string|false
- getInputOuterType() : string|false
- getInputTargetAttribute() : string|false
- getInputTargetAttributes() : string|false
- getInputTargetType() : string|false
- getLabel() : mixed
- getOptionSelects() : array<string|int, mixed>|false
- getProperty() : string|false
- hasError() : mixed
- labels() : mixed
- loadData() : mixed
- prepare() : PDOStatement
- Prepare a SQL statement via the application's PDO connection.
- primaryKey() : string
- Returns the primary key column name.
- property() : string
- rules() : mixed
- save() : bool
- Insert the current model instance into the database using its attributes.
- tableName() : string
- Name of the database table for the model.
- validate() : mixed
- addErrorByRule() : mixed
Constants
RULE_EMAIL
public
mixed
RULE_EMAIL
= 'email'
RULE_MATCH
public
mixed
RULE_MATCH
= 'match'
RULE_MAX
public
mixed
RULE_MAX
= 'max'
RULE_MIN
public
mixed
RULE_MIN
= 'min'
RULE_REQUIRED
public
mixed
RULE_REQUIRED
= 'required'
RULE_UNIQUE
public
mixed
RULE_UNIQUE
= 'unique'
Properties
$errors
public
array<string|int, mixed>
$errors
= []
Methods
addError()
public
addError(string $attribute, string $message) : mixed
Parameters
- $attribute : string
- $message : string
attributes()
public
static attributes() : mixed
attributesTypes()
Returns an array of column names mapped to their respective database data types.
public
abstract static attributesTypes() : array<string|int, mixed>
For example, if a column is a datetime, the value should be 'datetime'. If the column is a boolean, the value should be 'boolean'.
Return values
array<string|int, mixed>errorMessage()
public
errorMessage(mixed $rule) : mixed
Parameters
- $rule : mixed
errorMessages()
public
errorMessages() : mixed
findOne()
Fetch a single record by conditions and map it to the current subclass.
public
static findOne(array<string|int, mixed> $where) : static|false
Parameters
- $where : array<string|int, mixed>
-
Associative array of column => value filters.
Return values
static|false —Instance of the model or null if not found.
form()
public
form() : array<string|int, mixed>
Return values
array<string|int, mixed>getDisplayName()
public
abstract getDisplayName() : string
Return values
stringgetFirstError()
public
getFirstError(mixed $attribute) : mixed
Parameters
- $attribute : mixed
getInputInnerAttribute()
public
getInputInnerAttribute(string $property) : string|false
Parameters
- $property : string
Return values
string|falsegetInputInnerAttributes()
public
getInputInnerAttributes() : string|false
Return values
string|falsegetInputInnerType()
public
getInputInnerType() : string|false
Return values
string|falsegetInputOuterAttribute()
public
getInputOuterAttribute(string $property) : string|false
Parameters
- $property : string
Return values
string|falsegetInputOuterAttributes()
public
getInputOuterAttributes() : string|false
Return values
string|falsegetInputOuterType()
public
getInputOuterType() : string|false
Return values
string|falsegetInputTargetAttribute()
public
getInputTargetAttribute(string $property) : string|false
Parameters
- $property : string
Return values
string|falsegetInputTargetAttributes()
public
getInputTargetAttributes() : string|false
Return values
string|falsegetInputTargetType()
public
getInputTargetType() : string|false
Return values
string|falsegetLabel()
public
getLabel(mixed $attribute) : mixed
Parameters
- $attribute : mixed
getOptionSelects()
public
getOptionSelects(string $attribute) : array<string|int, mixed>|false
Parameters
- $attribute : string
Return values
array<string|int, mixed>|falsegetProperty()
public
getProperty(string $attribute, string $property) : string|false
Parameters
- $attribute : string
- $property : string
Return values
string|falsehasError()
public
hasError(mixed $attribute) : mixed
Parameters
- $attribute : mixed
labels()
public
labels() : mixed
loadData()
public
loadData(mixed $data) : mixed
Parameters
- $data : mixed
prepare()
Prepare a SQL statement via the application's PDO connection.
public
static prepare(string $sql) : PDOStatement
Parameters
- $sql : string
-
Raw SQL with named placeholders.
Return values
PDOStatementprimaryKey()
Returns the primary key column name.
public
static primaryKey() : string
Return values
stringproperty()
public
property(string $attribute) : string
Parameters
- $attribute : string
Return values
stringrules()
public
rules() : mixed
save()
Insert the current model instance into the database using its attributes.
public
save() : bool
Binds attributes as named parameters and executes the INSERT statement.
Return values
bool —True on successful execution.
tableName()
Name of the database table for the model.
public
abstract static tableName() : string
Return values
stringvalidate()
public
validate() : mixed
addErrorByRule()
protected
addErrorByRule(string $attribute, string $rule[, mixed $params = [] ]) : mixed
Parameters
- $attribute : string
- $rule : string
- $params : mixed = []