Skip to content

Instantly share code, notes, and snippets.

@ezimuel
Created May 20, 2014 15:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ezimuel/e2b528ba160197d0c773 to your computer and use it in GitHub Desktop.
Save ezimuel/e2b528ba160197d0c773 to your computer and use it in GitHub Desktop.
RPC with HAL JSON
<?php
namespace Test\V1\Rpc\Test;
use Zend\Mvc\Controller\AbstractActionController;
use ZF\ContentNegotiation\ViewModel;
use ZF\Hal\Entity;
use ZF\Hal\Link\Link;
class TestController extends AbstractActionController
{
public function testAction()
{
$id = 1;
$data = array ( 'name' => 'Enrico Zimuel', 'id' => $id );
$entity = new Entity($data, $id);
$entity->getLinks()->add(Link::factory(array(
'rel' => 'contacts',
'route' => array(
'name' => 'test.rest.user',
)
)));
return new ViewModel(array(
'payload' => $entity
));
}
}
@ezimuel
Copy link
Author

ezimuel commented May 30, 2014

I think we can add this information in this recipe https://www.apigility.org/documentation/recipes/hal-from-rpc, what do you think?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment