VO (Item) Renderers

ValueObject Renderers (aka Item Renderers) are classes that accept a known input type and use the data present in it to fill out a predefined template. The example here assumes HTML, but it doesn't necessarily have to be HTML you're outputting.

Getting Something To Render

Here I'll select a few users from the Db table using a selector. These user VOs are what we will be “rendering.”

This example may make the code to render a VO seem somewhat difficult to work with, but typically when you use the renderers, you will already have a handle on the VO(s) you want to render.

$picker = new UserSelector();
$userCollection = $picker->select()->username("LIKE", "%7%")->limit(0,4)->fetch(); AbstractSelector::fetch() using query: “SELECT * FROM `user` WHERE `user`.`username` LIKE '%7%' LIMIT 0, 4 ”

Create the UserTileIR Instance

Now we'll feed the user into the constructor of the UserTileIR so that it has the data it needs to complete the template. Then I will demonstrate a convenience method (getStyles()) that you'd use during design/development. The getStyles() method accepts an optional "parent" parameter that is prepended before each selector. You can use this to increase specificity and differentiate the rendered elements in different parts of the page.

$aUser = $userCollection->pop();
$userTile = new UserTileIR($aUser);//Create a new UserTile instance and initialize it with $aUser
echo "<h2><body> <em>{UserTile}</em> Styles</h2>" . $userTile->getStyles("body");// Get the applicable CSS selectors if the “UserTile”s are in the body tag AbstractCollection::pop() getting index: -1 of {0 - -1}
AbstractCollection::getRow()
Index (-1) not valid! Total: 0
AbstractCollection::pop() Unsetting
Removing the object at index #-1 from the collection.
New Collection Total: -1