Introducción a Zend Framework

 Aprendiendo Zend Framework

Apéndice

 Referencia de Zend Framework


  • Zend_Gdata
  • Zend_Http
  • Zend_InfoCard
  • Zend_Json
  • Zend_Layout
  • Zend_Ldap
  • Zend_Loader
  • Zend_Locale
  • Zend_Log
  • Zend_Mail
  • Zend_Markup
  • Zend_Measure
  • Zend_Memory
  • Zend_Mime
  • Zend_Navigation
  • Zend_Oauth
  • Zend_OpenId
  • Zend_Paginator
  • Zend_Pdf
  • Zend_ProgressBar
  • Zend_Queue
  • Zend_Reflection
  • Zend_Registry
  • Zend_Rest

  • Zend_Search_Lucene
  • Zend_Serializer
  • Zend_Server
  • Zend_Service
  • Zend_Session
  • Zend_Soap
  • Zend_Tag
  • Zend_Test
  • Zend_Text
  • Zend_TimeSync
  • Zend_Tool
  • Zend_Tool_Framework
  • Zend_Tool_Project
  • Zend_Translate
  • Zend_Uri
  • Zend_Validate
  • Zend_Version
  • Zend_View
  • Zend_Wildfire
  • Zend_XmlRpc
  • ZendX_Console_Process_Unix
  • ZendX_JQuery
  • Traducción al 26.9% - Actualizado el 2011-11-16 - Revisión 24249 - Versión ZF 1.11.x

    59.3. Zend_Rest_Server

    59.3.1. Introduction

    Zend_Rest_Server is intended as a fully-featured REST server.

    59.3.2. REST Server Usage

    Ejemplo 59.6. Basic Zend_Rest_Server Usage - Classes

    $server = new Zend_Rest_Server();
    $server->setClass('My_Service_Class');
    $server->handle();

    Ejemplo 59.7. Basic Zend_Rest_Server Usage - Functions

    /**
     * Say Hello
     *
     * @param string $who
     * @param string $when
     * @return string
     */
    function sayHello($who$when)
    {
        return 
    "Hello $who, Good $when";
    }

    $server = new Zend_Rest_Server();
    $server->addFunction('sayHello');
    $server->handle();

    59.3.3. Calling a Zend_Rest_Server Service

    To call a Zend_Rest_Server service, you must supply a GET/POST method argument with a value that is the method you wish to call. You can then follow that up with any number of arguments using either the name of the argument (i.e. "who") or using arg following by the numeric position of the argument (i.e. "arg1").

    [Nota] Numeric index

    Numeric arguments use a 1-based index.

    To call sayHello from the example above, you can use either:

    ?method=sayHello&who=Davey&when=Day

    or:

    ?method=sayHello&arg1=Davey&arg2=Day

    59.3.4. Sending A Custom Status

    When returning values, to return a custom status, you may return an array with a status key.

    Ejemplo 59.8. Returning Custom Status

    /**
     * Say Hello
     *
     * @param string $who
     * @param string $when
     * @return array
     */
    function sayHello($who$when)
    {
        return array(
    'msg' => "An Error Occurred"'status' => false);
    }

    $server = new Zend_Rest_Server();
    $server->addFunction('sayHello');
    $server->handle();

    59.3.5. Returning Custom XML Responses

    If you wish to return custom XML, simply return a DOMDocument, DOMElement or SimpleXMLElement object.

    Ejemplo 59.9. Return Custom XML

    /**
     * Say Hello
     *
     * @param string $who
     * @param string $when
     * @return SimpleXMLElement
     */
    function sayHello($who$when)
    {
        
    $xml ='<?xml version="1.0" encoding="ISO-8859-1"?>
    <mysite>
        <value>Hey $who! Hope you\'re having a good $when</value>
        <code>200</code>
    </mysite>'
    ;

        
    $xml simplexml_load_string($xml);
        return 
    $xml;
    }

    $server = new Zend_Rest_Server();
    $server->addFunction('sayHello');

    $server->handle();

    The response from the service will be returned without modification to the client.

    digg delicious meneame google twitter technorati facebook

    Comentarios

    Loading...