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

Resources

Zend_Amf provides tools for mapping resource types returned by service classes into data consumable by ActionScript.

In order to handle specific resource type, the user needs to create a plugin class named after the resource name, with words capitalized and spaces removed (so, resource type "mysql result" becomes MysqlResult), with some prefix, e.g. My_MysqlResult. This class should implement one method, parse(), receiving one argument - the resource - and returning the value that should be sent to ActionScript. The class should be located in the file named after the last component of the name, e.g. MysqlResult.php.

The directory containing the resource handling plugins should be registered with Zend_Amf type loader:

<?php
Zend_Amf_Parse_TypeLoader
::addResourceDirectory(
    
"My",
    
"application/library/resources/My"
);

For detailed discussion of loading plugins, please see the plugin loader section.

Default directory for Zend_Amf resources is registered automatically and currently contains handlers for "mysql result" and "stream" resources.

<?php
// Example class implementing handling resources of type mysql result
class Zend_Amf_Parse_Resource_MysqlResult
{
    
/**
     * Parse resource into array
     *
     * @param resource $resource
     * @return array
     */
    
public function parse($resource) {
        
$result = array();
        while(
$row mysql_fetch_assoc($resource)) {
            
$result[] = $row;
        }
        return 
$result;
    }
}

Trying to return unknown resource type (i.e., one for which no handler plugin exists) will result in an exception.

Zend Framework