PhpRiot
Become Zend Certified

Prepare for the ZCE exam using our quizzes (web or iPad/iPhone). More info...


When you're ready get 7.5% off your exam voucher using voucher CJQNOV23 at the Zend Store

Consuming Results

You can get one of two types of result object in response to a query.

The first group is represented by Zend_Service_Technorati_*ResultSet objects. A result set object is basically a collection of result objects. It extends the basic Zend_Service_Technorati_ResultSet class and implements the SeekableIterator PHP interface. The best way to consume a result set object is to loop over it with the PHP foreach() statement.

Example 848. Consuming a result set object

<?php
// create a new Zend_Service_Technorati
// with a valid API_KEY
$technorati = new Zend_Service_Technorati('VALID_API_KEY');

// search Technorati for PHP keyword
// $resultSet is an instance of Zend_Service_Technorati_SearchResultSet
$resultSet $technorati->search('PHP');

// loop over all result objects
foreach ($resultSet as $result) {
    
// $result is an instance of Zend_Service_Technorati_SearchResult
}

Because Zend_Service_Technorati_ResultSet implements the SeekableIterator interface, you can seek a specific result object using its position in the result collection.

Example 849. Seeking a specific result set object

<?php
// create a new Zend_Service_Technorati
// with a valid API_KEY
$technorati = new Zend_Service_Technorati('VALID_API_KEY');

// search Technorati for PHP keyword
// $resultSet is an instance of Zend_Service_Technorati_SearchResultSet
$resultSet $technorati->search('PHP');

// $result is an instance of Zend_Service_Technorati_SearchResult
$resultSet->seek(1);
$result $resultSet->current();

Note

SeekableIterator works as an array and counts positions starting from index 0. Fetching position number 1 means getting the second result in the collection.

The second group is represented by special standalone result objects. Zend_Service_Technorati_GetInfoResult, Zend_Service_Technorati_BlogInfoResult and Zend_Service_Technorati_KeyInfoResult act as wrappers for additional objects, such as Zend_Service_Technorati_Author and Zend_Service_Technorati_Weblog.

Example 850. Consuming a standalone result object

<?php
// create a new Zend_Service_Technorati
// with a valid API_KEY
$technorati = new Zend_Service_Technorati('VALID_API_KEY');

// get info about weppos author
$result $technorati->getInfo('weppos');

$author $result->getAuthor();
echo 
'<h2>Blogs authored by ' $author->getFirstName() . " " .
          
$author->getLastName() . '</h2>';
echo 
'<ol>';
foreach (
$result->getWeblogs() as $weblog) {
    echo 
'<li>' $weblog->getName() . '</li>';
}
echo 
"</ol>";

Please read the Zend_Service_Technorati Classes section for further details about response classes.

Zend Framework