Core/getElements

From PunchCMS
Jump to: navigation, search

PCMS_Client->getElements([elementApiName], [getFirst], [recursive])

Overview

Get a collection of elements and folders with an optional specific api name from the root folder.

Arguments

elementApiName [string, optional]
API name of the elements you are looking for.

getFirst [boolean, optional]
Indicate if you want to get only the first found Element or a collection of Elements. Default is FALSE.
This is deprecated. You should use the get() method instead.

recursive [boolean, optional]
Indicate if you want to search trough the tree or only on the first level. Setting this to TRUE can be very time consuming. Default is FALSE.

Returns

If Elements are found matching the criteria this method returns a valid Elements object. Otherwise an empty collection. That way you can test if you get a valid return using the count() method.

If the getFirst argument was set to TRUE and an Element was found it will return a valid Element object. Otherwise NULL.

Example

$objCms = PCMS_Client::getInstance();
 
// Get a collection of Elements with API name 'Item'.
$objElements = $objCms->getElements("Item");
foreach ($objElements as $objElement) {
    // Loop through the collection.
}