User Tools

Site Tools


collection_class

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

collection_class [2020/02/17 09:58] – created sahlcollection_class [2020/02/17 10:29] (current) sahl
Line 5: Line 5:
 ===== Basic usage ===== ===== Basic usage =====
  
-Usually the Collection is the result of using the [[class_filter|Filter]] object, but it can be spawned on its own, passing a Datarecord or an array of Datarecords into the constructor, or adding it later using the add function.+Usually the Collection is the result of using the [[filter_class|Filter]] object, but it can be spawned on its own, passing a Datarecord or an array of Datarecords into the constructor, or adding it later using the add function.
  
 <code php> <code php>
Line 14: Line 14:
 A datarecord can only contain objects of the same type and will adapt to the first object it receives.  A datarecord can only contain objects of the same type and will adapt to the first object it receives. 
  
-The collection can be sorted by a specific field using ''sort'' and data can be retrieved using the different get-functionssuch as:+The collection can be sorted by a specific field using ''sort'' and implements the PHP Iterator interfaceso it can be used like any iterator:
  
 <code php> <code php>
 $collection->sort('full_name'); $collection->sort('full_name');
-foreach ($collection->getAll() as $user) {+foreach ($collection as $user) {
     echo $user->full_name;     echo $user->full_name;
 } }
 +</code>
  
 +There are also some more sofisticated get-functions such as getting the value of a single field from the objects in the collection
 +
 +<code php>
 foreach ($collection->getAllFullValues('full_name') as $value) { foreach ($collection->getAllFullValues('full_name') as $value) {
    echo $value;    echo $value;
 } }
 </code> </code>
 +
 +
collection_class.1581933483.txt.gz · Last modified: 2020/02/17 09:58 by sahl

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki