PHP Class Contao\Model\Collection

The class handles traversing a set of models and lazy loads the database result rows upon their first usage.
Inheritance: implements ArrayAccess, implements Countable, implements IteratorAggregate
Datei anzeigen Open project: contao/core-bundle Class Usage Examples

Protected Properties

Property Type Description
$arrModels Contao\Model[] Models
$intIndex integer Current index
$strTable string Table name

Public Methods

Method Description
__construct ( array $arrModels, string $strTable ) Create a new collection
__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
count ( ) : integer Return the number of rows in the result set
createFromDbResult ( Result $objResult, string $strTable ) : static Create a new collection from a database result
current ( ) : Model Return the current model
delete ( ) : integer Delete the current model and return the number of affected rows
fetchAll ( ) : array Fetch all columns of every row
fetchEach ( string $strKey ) : array Fetch a column of each row
first ( ) : static Go to the first row
getIterator ( ) : ArrayIterator Retrieve the iterator object
getModels ( ) : Model[] Return the models as array
getRelated ( string $strKey ) : Model | static Lazy load related records
last ( ) : static Go to the last row
next ( ) : static | boolean Go to the next row
offsetExists ( integer $offset ) : boolean Check whether an offset exists
offsetGet ( integer $offset ) : Model | null Retrieve a particular offset
offsetSet ( integer $offset, mixed $value ) Set a particular offset
offsetUnset ( integer $offset ) Unset a particular offset
prev ( ) : static | false Go to the previous row
reset ( ) : static Reset the model
row ( ) : array Return the current row as associative array
save ( ) : static Save the current model
setRow ( array $arrData ) : static Set the current row from an array

Method Details

__construct() public method

Create a new collection
public __construct ( array $arrModels, string $strTable )
$arrModels array An array of models
$strTable string The table name

__get() public method

Return an object property
public __get ( string $strKey ) : mixed | null
$strKey string The property name
return mixed | null The property value or null

__isset() public method

Check whether a property is set
public __isset ( string $strKey ) : boolean
$strKey string The property name
return boolean True if the property is set

__set() public method

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

count() public method

Return the number of rows in the result set
public count ( ) : integer
return integer The number of rows

createFromDbResult() public static method

Create a new collection from a database result
public static createFromDbResult ( Result $objResult, string $strTable ) : static
$objResult Contao\Database\Result The database result object
$strTable string The table name
return static The model collection

current() public method

Return the current model
public current ( ) : Model
return Contao\Model The model object

delete() public method

Delete the current model and return the number of affected rows
public delete ( ) : integer
return integer The number of affected rows

fetchAll() public method

Fetch all columns of every row
public fetchAll ( ) : array
return array An array with all rows and columns

fetchEach() public method

Fetch a column of each row
public fetchEach ( string $strKey ) : array
$strKey string The property name
return array An array with all property values

first() public method

Go to the first row
public first ( ) : static
return static The model collection object

getIterator() public method

Retrieve the iterator object
public getIterator ( ) : ArrayIterator
return ArrayIterator The iterator object

getModels() public method

Return the models as array
public getModels ( ) : Model[]
return Contao\Model[] An array of models

getRelated() public method

Lazy load related records
public getRelated ( string $strKey ) : Model | static
$strKey string The property name
return Contao\Model | static The model or a model collection if there are multiple rows

last() public method

Go to the last row
public last ( ) : static
return static The model collection object

next() public method

Go to the next row
public next ( ) : static | boolean
return static | boolean The model collection object or false if there is no next row

offsetExists() public method

Check whether an offset exists
public offsetExists ( integer $offset ) : boolean
$offset integer The offset
return boolean True if the offset exists

offsetGet() public method

Retrieve a particular offset
public offsetGet ( integer $offset ) : Model | null
$offset integer The offset
return Contao\Model | null The model or null

offsetSet() public method

Set a particular offset
public offsetSet ( integer $offset, mixed $value )
$offset integer The offset
$value mixed The value to set

offsetUnset() public method

Unset a particular offset
public offsetUnset ( integer $offset )
$offset integer The offset

prev() public method

Go to the previous row
public prev ( ) : static | false
return static | false The model collection object or false if there is no previous row

reset() public method

Reset the model
public reset ( ) : static
return static The model collection object

row() public method

Return the current row as associative array
public row ( ) : array
return array The current row as array

save() public method

Save the current model
public save ( ) : static
return static The model collection object

setRow() public method

Set the current row from an array
public setRow ( array $arrData ) : static
$arrData array The row data as array
return static The model collection object

Property Details

$arrModels protected_oe property

Models
protected Model[],Contao $arrModels
return Contao\Model[]

$intIndex protected_oe property

Current index
protected int $intIndex
return integer

$strTable protected_oe property

Table name
protected string $strTable
return string