Model class abstract
Framework\MVC\Model
Class Model.
Implements:
Framework\MVC\ModelInterface
Defined in libraries/mvc/src/Model.php
Properties #
- $models
- -
- $connectionRead
- Database connection instance name for read operations.
- $connectionWrite
- Database connection instance name for write operations.
- $table
- Table name.
- $primaryKey
- Table Primary Key.
- $protectPrimaryKey
- Prevents Primary Key changes on INSERT and UPDATE.
- $returnType
- Fetched item return type.
- $allowedFields
- Allowed columns for INSERT and UPDATE.
- $autoTimestamps
- Auto set timestamp fields.
- $fieldCreated
- The timestamp field for 'created at' time when $autoTimestamps is true.
- $fieldUpdated
- The timestamp field for 'updated at' time when $autoTimestamps is true.
- $timestampFormat
- The timestamp format used on database write operations.
- $validation
- The Model Validation instance.
- $validationLabels
- Validation field labels.
- $validationMessages
- Validation error messages.
- $validationRules
- Validation rules.
- $validationValidators
- Validation Validators.
- $pager
- The Pager instance.
- $pagerView
- Default pager view.
- $pagerQuery
- -
- $pagerAllowedQueries
- -
- $pagerUrl
- Pager URL.
- $cacheActive
- -
- $cacheInstance
- -
- $cacheTtl
- -
- $cacheDataNotFound
- -
- $languageInstance
- -
- $columnCase
- -
$models
$connectionRead
Database connection instance name for read operations.
$connectionWrite
Database connection instance name for write operations.
$table
Table name.
$primaryKey
Table Primary Key.
$protectPrimaryKey
Prevents Primary Key changes on INSERT and UPDATE.
$returnType
Fetched item return type.
$allowedFields
Allowed columns for INSERT and UPDATE.
$autoTimestamps
Auto set timestamp fields.
$fieldCreated
The timestamp field for 'created at' time when $autoTimestamps is true.
$fieldUpdated
The timestamp field for 'updated at' time when $autoTimestamps is true.
$timestampFormat
The timestamp format used on database write operations.
$validation
The Model Validation instance.
$validationLabels
Validation field labels.
$validationMessages
Validation error messages.
$validationRules
Validation rules.
$validationValidators
Validation Validators.
$pager
The Pager instance.
$pagerView
Default pager view.
$pagerQuery
$pagerAllowedQueries
$pagerUrl
Pager URL.
$cacheActive
$cacheInstance
$cacheTtl
$cacheDataNotFound
$languageInstance
$columnCase
Methods #
- __call()
- -
- count()
- A basic function to count rows in the table.
- create()
- Insert a new row.
- createBy()
- Insert a new row and return the inserted column value.
- delete()
- Delete based on Primary Key.
- deleteBy()
- Delete based on column value.
- find()
- Alias of {@see Model::read()}.
- findAll()
- Alias of {@see Model::list()}.
- findBy()
- Alias of {@see Model::readBy()}.
- get()
- Get same Model instance.
- getErrors()
- Get Validation errors.
- getPager()
- Get the Pager.
- getValidationMessages()
- -
- getValidationValidators()
- -
- list()
- List rows, optionally with limit and offset.
- paginate()
- A basic function to paginate all rows of the table.
- read()
- Read a row based on Primary Key.
- readBy()
- Read a row by column name and value.
- replace()
- Replace based on Primary Key and return the number of affected rows.
- replaceBy()
- Replace based on column value and return the number of affected rows.
- save()
- Save a row. Update if the Primary Key is present, otherwise insert a new row.
- update()
- Update based on Primary Key and return the number of affected rows.
- updateBy()
- Update based on column value and return the number of affected rows.
- checkMysqliException()
- -
- checkPrimaryKey()
- -
- convertCase()
- Convert a value to specific case.
- filterAllowedFields()
- -
- getAllowedFields()
- -
- getCache()
- -
- getCacheDataNotFound()
- -
- getCacheInstance()
- -
- getCacheKey()
- -
- getCacheTtl()
- -
- getConnectionRead()
- -
- getConnectionWrite()
- -
- getDatabaseToRead()
- -
- getDatabaseToWrite()
- -
- getFieldCreated()
- -
- getFieldUpdated()
- -
- getLanguage()
- -
- getLanguageInstance()
- -
- getPagerAllowedQueries()
- Get allowed queries to be used in the Pager.
- getPagerQuery()
- Get the custom query to be used in the Pager.
- getPagerUrl()
- Get the custom URL to be used in the Pager.
- getPagerView()
- Get the custom view to be used in the Pager.
- getPrimaryKey()
- -
- getReturnType()
- -
- getTable()
- -
- getTimestamp()
- Used to auto set the timestamp fields.
- getTimestampFormat()
- -
- getValidation()
- -
- getValidationLabels()
- -
- getValidationRules()
- -
- isAutoTimestamps()
- -
- isCacheActive()
- -
- isProtectPrimaryKey()
- -
- makeArray()
- -
- makeEntity()
- -
- makePageLimitAndOffset()
- -
- makeTableName()
- -
- readRow()
- -
- readWithCache()
- -
- sanitizePageNumber()
- -
- setDuplicateEntryError()
- Set "Duplicate entry" as 'unique' error in the Validation.
- setPager()
- Set the Pager.
- timezone()
- Get the timezone from database write connection config. As fallback, uses the UTC timezone.
- updateCachedRow()
- -
__call()
- string $method
- array $arguments
count()
A basic function to count rows in the table.
- array $where - Array in this format: `[['id', '=', 25]]`
create()
Insert a new row.
- \Framework\MVC\Entity|stdClass|array $data
createBy()
Insert a new row and return the inserted column value.
- string $column - Column name
- \Framework\MVC\Entity|stdClass|array $data
delete()
Delete based on Primary Key.
- string|int $id
deleteBy()
Delete based on column value.
- string $column
- string|int $value
find()
Alias of {@see Model::read()}.
- string|int $id
findAll()
Alias of {@see Model::list()}.
Find all rows with limit and offset.
- ?int $limit
- ?int $offset
findBy()
Alias of {@see Model::readBy()}.
Find a row by column name and value.
- string $column
- string|int $value
get()
Get same Model instance.
- string $class
getErrors()
Get Validation errors.
getPager()
Get the Pager.
Allowed only after calling a method that sets the Pager.
getValidationMessages()
getValidationValidators()
list()
List rows, optionally with limit and offset.
- ?int $limit
- ?int $offset
paginate()
A basic function to paginate all rows of the table.
- mixed $page - The current page
- mixed $perPage - Items per page
- array $where - Array in this format: `[['id', '=', 25]]`
- array|string|null $orderBy - Order by columns
- string $orderByDirection - asc or desc
read()
Read a row based on Primary Key.
- string|int $id
readBy()
Read a row by column name and value.
- string $column
- string|int $value
replace()
Replace based on Primary Key and return the number of affected rows.
Most used with HTTP PUT method.
- string|int $id
- \Framework\MVC\Entity|stdClass|array $data
replaceBy()
Replace based on column value and return the number of affected rows.
- string $column
- string|int $value
- \Framework\MVC\Entity|stdClass|array $data
save()
Save a row. Update if the Primary Key is present, otherwise insert a new row.
- \Framework\MVC\Entity|stdClass|array $data
update()
Update based on Primary Key and return the number of affected rows.
- string|int $id
- \Framework\MVC\Entity|stdClass|array $data
updateBy()
Update based on column value and return the number of affected rows.
- string $column
- string|int $value
- \Framework\MVC\Entity|stdClass|array $data
checkMysqliException()
- mysqli_sql_exception $exception
checkPrimaryKey()
- string|int $id
convertCase()
Convert a value to specific case.
- string $value
- string $case - camel, pascal or snake
filterAllowedFields()
- array $data
getAllowedFields()
getCache()
getCacheDataNotFound()
getCacheInstance()
getCacheKey()
- array $fields
getCacheTtl()
getConnectionRead()
getConnectionWrite()
getDatabaseToRead()
getDatabaseToWrite()
getFieldCreated()
getFieldUpdated()
getLanguage()
getLanguageInstance()
getPagerAllowedQueries()
Get allowed queries to be used in the Pager.
getPagerQuery()
Get the custom query to be used in the Pager.
getPagerUrl()
Get the custom URL to be used in the Pager.
getPagerView()
Get the custom view to be used in the Pager.
getPrimaryKey()
getReturnType()
getTable()
getTimestamp()
Used to auto set the timestamp fields.
getTimestampFormat()
getValidation()
getValidationLabels()
getValidationRules()
isAutoTimestamps()
isCacheActive()
isProtectPrimaryKey()
makeArray()
- \Framework\MVC\Entity|stdClass|array $data
makeEntity()
- array $data
makePageLimitAndOffset()
- int $page
- int $perPage
makeTableName()
readRow()
- string $column
- string|int $value
readWithCache()
- string $column
- string|int $value
sanitizePageNumber()
- int $number
setDuplicateEntryError()
Set "Duplicate entry" as 'unique' error in the Validation.
NOTE: We will get the index key name and not the column name. Usually the
names are the same. If table have different column and index names,
override this method and get the column name from the information_schema
table.
- string $message - The "Duplicate entry" message from the mysqli_sql_exception
setPager()
Set the Pager.
- \Framework\Pagination\Pager $pager
timezone()
Get the timezone from database write connection config. As fallback, uses the UTC timezone.
updateCachedRow()
- string $column
- string|int $value