Prev | Current Page 326 | Next

Rob Allen, Nick Lo, and Steven Brown

"Zend Framework in Action"


Listing 11.14 Our Places service concrete class
class ServicePlaces implements Places_Service_Place_Interface
{
public function getPlace($id)
{
$placesFinder = new Places();
$place = $placesFinder->find($id);
return $place->current()->toArray(); A
}
public function getReviews($id)
{
$reviewsFinder = new Reviews();
$rowset = $reviewsFinder->fetchByPlaceId($id);
return $rowset->toArray(); A
}
}
A Note that we change the query results from an object to an array as Zend_Rest_Server will not process the object
Now that we have the concrete class we can attach it to Zend_Rest_Server with the same approach that we
covered with Zend_XmlRpc_Server.
Listing 11.15 Our REST server
class RestController extends Zend_Controller_Action
{
protected $_server;
public function init()
{
$this->_server = new Zend_Rest_Server();
$this->_helper->viewRenderer->setNoRender();
}
public function indexAction()
{
require_once 'ServicePlaces.php';
$this->_server->setClass('ServicePlaces');
$this->_server->handle();
}
}
Licensed to Menshu You
Zend Framework in Action (Ch01) Manning Publications Co. 33
Listing 11.15 shows our REST server set-up within an action controller and accessible via an HTTP GET
or POST that must supply the name of the service method you wish to invoke.


Pages:
314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338
botox Kraków wyświetlacz xperia Wczasy nad morzem baseny ogrodowe tłumacz niemieckiego