Happpi PHP Library

getCategories()

Retrieves a list of categories

Return Type

Array of type: CurtAPICategory

Required Parameters

    None

Optional Parameters

    None

Dependencies

    Optional: $category->setParentID(int $value)

Example:


<!-- getCategories() -->
<?php
	require_once('libraries/happpi/LoadAll.php'); // points to the LoadAll.php file for loading the library.

	// once the library is required, you can now use one of the main "interaction" classes.
	// These interaction classes contain methods that get information from our REST API and
	// converts them to PHP objects for you to use.
	$Cat = new CurtCategory(); // create a new category object to gain access to its functions.
	$categories = $Cat->getCategories(); // call getCategories which returns an array of APICategory Objects.
	
	echo "<h2>All Categories:</h2>";	
	echo "<ul>";
	foreach($categories as $categoryObj){
		// use the getter to get the catTitle Property for each Category Object in the array.
		echo "<li>" . $categoryObj->getCatTitle() . "</li>";
	}
	echo "</ul>";

	// getCategories also has an optional Dependency setParentID() which is used if you want to get all the child categories of a certain category.
	echo "<h2>Child Categories of Hitches</h2>";
	$Cat->setParentID(1); // use the optional dependency to set the Parent Category.
	$categories = $Cat->getCategories(); // use the getCategories method to return all the child categories of hitches (catID of 1)

	echo "<ul>";
	foreach($categories as $categoryObj){
		echo "<li>" . $categoryObj->getCatTitle() . "</li>";
	}
	echo "</ul>";
	
?>