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
파일 보기 프로젝트 열기: contao/core-bundle 1 사용 예제들

보호된 프로퍼티들

프로퍼티 타입 설명
$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