Skip to the content
Documentation

list

No ratings yet

Summary

Fetches a collection of classes.

Usage

fetch( 'class', 'list', hash( [ 'class_filter', class_filter ],
                              [ 'sort_by',      sort_by      ] ) )

Parameters

Name Type Description Required
class_filter array The classes that should be filtered. No.
sort_by array The sorting mechanism that should be used. No.

Returns

Array of ezcontentclass objects or FALSE.

Description

This function fetches a collection of classes. The optional "class_filter" parameter can be used to fetch only a given set of classes. This parameter must be either an array of class ID numbers or an array of class identifier strings (in other words: mixing is not possible). If the "class_filter" array is omitted, all classes will be returned.

The optional "sort_by" parameter makes it possible to sort the result in different ways. This parameter must be provided as an array. The first element of the array is the desired sorting method. The second element of the array is the sorting direction, it can be either true() or false() - ascending or descending. The following table shows the sorting methods that can be used.

Sorting method Description
id The classes are sorted by their ID numbers.
name The classes are sorted by their names.

You can only use one sorting method per query. In other words, you can sort the classes by name or by ID, but not both in the same query.

Examples

Example 1

{def $classes=fetch( 'class', 'list' )}

{foreach $classes as $class}
    {$class.name|wash} <br />
{/foreach}

Outputs the names of all classes.

Example 2

{def $classes=fetch( 'class', 'list', hash( 'class_filter', array( 'folder', 'article' ) ) )}

{foreach $classes as $class}
    {$class.name|wash} <br />
{/foreach}

Outputs the names of the classes identified by the strings "folder" and "article".

Example 3

{def $classes=fetch( 'class', 'list',
                     hash( 'class_filter', array( 1, 2, 3 ),
                           'sort_by', array( 'name', true() ) ) )}

The function will fetch classes number 1, 2 and 3. The fetched classes will be sorted by name in ascending order.

Contributors

Comments

Add a comment

Comments are read by a moderator before they appear.