PHP Класс Contao\Model

The class allows you to find and automatically join database records and to convert the result into objects. It also supports creating new objects and persisting them in the database. Usage: Write $user = new UserModel(); $user->name = 'Leo Feyer'; $user->city = 'Wuppertal'; $user->save(); Read $user = UserModel::findByCity('Wuppertal'); while ($user->next()) { echo $user->name; }
Наследование: extends System
Показать файл Открыть проект Примеры использования класса

Защищенные свойства (Protected)

Свойство Тип Описание
$arrClassNames array Class name cache
$arrData array Data
$arrModified array Modified keys
$arrRelated array Related
$arrRelations array Relations
$blnPreventSaving boolean Prevent saving
$strPk string Primary key
$strTable string Table name

Открытые методы

Метод Описание
__callStatic ( string $name, array $args ) : static | Collection | null Magic method to map Model::findByName() to Model::findBy('name')
__clone ( ) Unset the primary key when cloning an object
__construct ( Result $objResult = null ) Load the relations and optionally process a result set
__get ( string $strKey ) : mixed | null Return an object property
__isset ( string $strKey ) : boolean Check whether a property is set
__set ( string $strKey, mixed $varValue ) Set an object property
attach ( ) Attach the model to the registry
cloneOriginal ( ) : static Clone a model with its original values
countAll ( ) : integer Return the total number of rows
countBy ( mixed $strColumn = null, mixed $varValue = null, array $arrOptions = [] ) : integer Return the number of records matching certain criteria
current ( ) : static Return the object instance
delete ( ) : integer Delete the current record and return the number of affected rows
detach ( boolean $blnKeepClone = true ) Detach the model from the registry
findAll ( array $arrOptions = [] ) : Collection | null Find all records
findBy ( mixed $strColumn, mixed $varValue, array $arrOptions = [] ) : static | Collection | null Find records by various criteria
findByIdOrAlias ( mixed $varId, array $arrOptions = [] ) : static Find a single record by its ID or alias
findByPk ( mixed $varValue, array $arrOptions = [] ) : static Find a single record by its primary key
findMultipleByIds ( array $arrIds, array $arrOptions = [] ) : Collection | null Find multiple records by their IDs
findOneBy ( mixed $strColumn, mixed $varValue, array $arrOptions = [] ) : static Find a single record by various criteria
getClassFromTable ( string $strTable ) : string Compile a Model class name from a table name (e.g. tl_form_field becomes FormFieldModel)
getPk ( ) : string Return the name of the primary key
getRelated ( string $strKey, array $arrOptions = [] ) : static | Collection | null Lazy load related records
getTable ( ) : string Return the name of the related table
getUniqueFields ( ) : array Return an array of unique field/column names (without the PK)
isModified ( ) : boolean Return true if the model has been modified
markModified ( string $strKey ) Mark a field as modified
mergeRow ( array $arrData ) : static Set the current record from an array preserving modified but unsaved fields
onRegister ( Registry $registry ) Called when the model is attached to the model registry
onUnregister ( Registry $registry ) Called when the model is detached from the model registry
originalRow ( ) : array Return the original values as associative array
preventSaving ( boolean $blnKeepClone = true ) Prevent saving the model
refresh ( ) Reload the data from the database discarding all modifications
row ( ) : array Return the current record as associative array
save ( ) : static Save the current record
setRow ( array $arrData ) : static Set the current record from an array

Защищенные методы

Метод Описание
buildCountQuery ( array $arrOptions ) : string Build a query based on the given options to count the number of records
buildFindQuery ( array $arrOptions ) : string Build a query based on the given options
createCollection ( array $arrModels, string $strTable ) : Collection Create a Model\Collection object
createCollectionFromDbResult ( Result $objResult, string $strTable ) : Collection Create a new collection from a database result
createModelFromDbResult ( Result $objResult ) : static Create a model from a database result
find ( array $arrOptions ) : static | Collection | null Find records and return the model or model collection
postFind ( Result $objResult ) : Result Modify the database result before the model is created
postSave ( integer $intType ) Modify the current row after it has been stored in the database
preFind ( Statement $objStatement ) : Statement Modify the database statement before it is executed
preSave ( array $arrSet ) : array Modify the current row before it is stored in the database

Описание методов

__callStatic() публичный статический Метод

Magic method to map Model::findByName() to Model::findBy('name')
public static __callStatic ( string $name, array $args ) : static | Collection | null
$name string The method name
$args array The passed arguments
Результат static | Contao\Model\Collection | null A model or model collection

__clone() публичный Метод

Unset the primary key when cloning an object
public __clone ( )

__construct() публичный Метод

Load the relations and optionally process a result set
public __construct ( Result $objResult = null )
$objResult Contao\Database\Result An optional database result

__get() публичный Метод

Return an object property
public __get ( string $strKey ) : mixed | null
$strKey string The property key
Результат mixed | null The property value or null

__isset() публичный Метод

Check whether a property is set
public __isset ( string $strKey ) : boolean
$strKey string The property key
Результат boolean True if the property is set

__set() публичный Метод

Set an object property
public __set ( string $strKey, mixed $varValue )
$strKey string The property name
$varValue mixed The property value

attach() публичный Метод

Attach the model to the registry
public attach ( )

buildCountQuery() защищенный статический Метод

Build a query based on the given options to count the number of records
protected static buildCountQuery ( array $arrOptions ) : string
$arrOptions array The options array
Результат string The query string

buildFindQuery() защищенный статический Метод

Build a query based on the given options
protected static buildFindQuery ( array $arrOptions ) : string
$arrOptions array The options array
Результат string The query string

cloneOriginal() публичный Метод

Clone a model with its original values
public cloneOriginal ( ) : static
Результат static The model

countAll() публичный статический Метод

Return the total number of rows
public static countAll ( ) : integer
Результат integer The total number of rows

countBy() публичный статический Метод

Return the number of records matching certain criteria
public static countBy ( mixed $strColumn = null, mixed $varValue = null, array $arrOptions = [] ) : integer
$strColumn mixed An optional property name
$varValue mixed An optional property value
$arrOptions array An optional options array
Результат integer The number of matching rows

createCollection() защищенный статический Метод

Create a Model\Collection object
protected static createCollection ( array $arrModels, string $strTable ) : Collection
$arrModels array An array of models
$strTable string The table name
Результат Contao\Model\Collection The Model\Collection object

createCollectionFromDbResult() защищенный статический Метод

Create a new collection from a database result
protected static createCollectionFromDbResult ( Result $objResult, string $strTable ) : Collection
$objResult Contao\Database\Result The database result object
$strTable string The table name
Результат Contao\Model\Collection The model collection

createModelFromDbResult() защищенный статический Метод

Create a model from a database result
protected static createModelFromDbResult ( Result $objResult ) : static
$objResult Contao\Database\Result The database result object
Результат static The model

current() публичный Метод

Return the object instance
public current ( ) : static
Результат static The model object

delete() публичный Метод

Delete the current record and return the number of affected rows
public delete ( ) : integer
Результат integer The number of affected rows

detach() публичный Метод

Detach the model from the registry
public detach ( boolean $blnKeepClone = true )
$blnKeepClone boolean Keeps a clone of the model in the registry

find() защищенный статический Метод

Supported options: * column: the field name * value: the field value * limit: the maximum number of rows * offset: the number of rows to skip * order: the sorting order * eager: load all related records eagerly
protected static find ( array $arrOptions ) : static | Collection | null
$arrOptions array The options array
Результат static | Contao\Model\Collection | null A model, model collection or null if the result is empty

findAll() публичный статический Метод

Find all records
public static findAll ( array $arrOptions = [] ) : Collection | null
$arrOptions array An optional options array
Результат Contao\Model\Collection | null The model collection or null if the result is empty

findBy() публичный статический Метод

Find records by various criteria
public static findBy ( mixed $strColumn, mixed $varValue, array $arrOptions = [] ) : static | Collection | null
$strColumn mixed The property name
$varValue mixed The property value
$arrOptions array An optional options array
Результат static | Contao\Model\Collection | null A model, model collection or null if the result is empty

findByIdOrAlias() публичный статический Метод

Find a single record by its ID or alias
public static findByIdOrAlias ( mixed $varId, array $arrOptions = [] ) : static
$varId mixed The ID or alias
$arrOptions array An optional options array
Результат static The model or null if the result is empty

findByPk() публичный статический Метод

Find a single record by its primary key
public static findByPk ( mixed $varValue, array $arrOptions = [] ) : static
$varValue mixed The property value
$arrOptions array An optional options array
Результат static The model or null if the result is empty

findMultipleByIds() публичный статический Метод

Find multiple records by their IDs
public static findMultipleByIds ( array $arrIds, array $arrOptions = [] ) : Collection | null
$arrIds array An array of IDs
$arrOptions array An optional options array
Результат Contao\Model\Collection | null The model collection or null if there are no records

findOneBy() публичный статический Метод

Find a single record by various criteria
public static findOneBy ( mixed $strColumn, mixed $varValue, array $arrOptions = [] ) : static
$strColumn mixed The property name
$varValue mixed The property value
$arrOptions array An optional options array
Результат static The model or null if the result is empty

getClassFromTable() публичный статический Метод

Compile a Model class name from a table name (e.g. tl_form_field becomes FormFieldModel)
public static getClassFromTable ( string $strTable ) : string
$strTable string The table name
Результат string The model class name

getPk() публичный статический Метод

Return the name of the primary key
public static getPk ( ) : string
Результат string The primary key

getRelated() публичный Метод

Lazy load related records
public getRelated ( string $strKey, array $arrOptions = [] ) : static | Collection | null
$strKey string The property name
$arrOptions array An optional options array
Результат static | Contao\Model\Collection | null The model or a model collection if there are multiple rows

getTable() публичный статический Метод

Return the name of the related table
public static getTable ( ) : string
Результат string The table name

getUniqueFields() публичный статический Метод

Return an array of unique field/column names (without the PK)
public static getUniqueFields ( ) : array
Результат array

isModified() публичный Метод

Return true if the model has been modified
public isModified ( ) : boolean
Результат boolean True if the model has been modified

markModified() публичный Метод

Mark a field as modified
public markModified ( string $strKey )
$strKey string The field key

mergeRow() публичный Метод

Set the current record from an array preserving modified but unsaved fields
public mergeRow ( array $arrData ) : static
$arrData array The data record
Результат static The model object

onRegister() публичный Метод

Called when the model is attached to the model registry
public onRegister ( Registry $registry )
$registry Contao\Model\Registry The model registry

onUnregister() публичный Метод

Called when the model is detached from the model registry
public onUnregister ( Registry $registry )
$registry Contao\Model\Registry The model registry

originalRow() публичный Метод

Return the original values as associative array
public originalRow ( ) : array
Результат array The original data

postFind() защищенный статический Метод

Modify the database result before the model is created
protected static postFind ( Result $objResult ) : Result
$objResult Contao\Database\Result The database result object
Результат Contao\Database\Result The database result object

postSave() защищенный Метод

Modify the current row after it has been stored in the database
protected postSave ( integer $intType )
$intType integer The query type (Model::INSERT or Model::UPDATE)

preFind() защищенный статический Метод

Modify the database statement before it is executed
protected static preFind ( Statement $objStatement ) : Statement
$objStatement Contao\Database\Statement The database statement object
Результат Contao\Database\Statement The database statement object

preSave() защищенный Метод

Modify the current row before it is stored in the database
protected preSave ( array $arrSet ) : array
$arrSet array The data array
Результат array The modified data array

preventSaving() публичный Метод

Prevent saving the model
public preventSaving ( boolean $blnKeepClone = true )
$blnKeepClone boolean Keeps a clone of the model in the registry

refresh() публичный Метод

Reload the data from the database discarding all modifications
public refresh ( )

row() публичный Метод

Return the current record as associative array
public row ( ) : array
Результат array The data record

save() публичный Метод

Save the current record
public save ( ) : static
Результат static The model object

setRow() публичный Метод

Set the current record from an array
public setRow ( array $arrData ) : static
$arrData array The data record
Результат static The model object

Описание свойств

$arrClassNames защищенное статическое свойство

Class name cache
protected static array $arrClassNames
Результат array

$arrData защищенное свойство

Data
protected array $arrData
Результат array

$arrModified защищенное свойство

Modified keys
protected array $arrModified
Результат array

$arrRelated защищенное свойство

Related
protected array $arrRelated
Результат array

$arrRelations защищенное свойство

Relations
protected array $arrRelations
Результат array

$blnPreventSaving защищенное свойство

Prevent saving
protected bool $blnPreventSaving
Результат boolean

$strPk защищенное статическое свойство

Primary key
protected static string $strPk
Результат string

$strTable защищенное статическое свойство

Table name
protected static string $strTable
Результат string