loop
— Get an iterator for looping over an array of records.
Summary
loop()
is designed to make looping through records for a browse page easier.
You can either pass in an array of record to loop through or, more commonly, the name of the model (e.g. ‘items’ or ‘collections’), whose records have already been set on the page.
- loop($recordsVar, $records = null)
Get an iterator for looping over an array of records.
- Parameters:
$recordsVar (
string
) – The name of the variable the records are stored in.$records (
array|null
) –
- Returns:
Omeka_Record_Iterator
Usage
Usually, the $recordsVar
parameter is a string name of the model whose records have already been set in the view by the controller.
This will be the name of the table, i.e., the pluralized, underscored name of the model. For example, a CamelCase model name like “CsvImport_Import” should be “csv_import_imports”.
The string will be converted to the table name. Thus, csv_import_imports
and CsvImport_Import
have exactly the same effect (provided the same convention was used in setting the records to loop in the view).