Skip to content

Instantly share code, notes, and snippets.

@weierophinney
Last active January 2, 2016 17:39
Show Gist options
  • Save weierophinney/8338534 to your computer and use it in GitHub Desktop.
Save weierophinney/8338534 to your computer and use it in GitHub Desktop.
How to manipulate the data returned via PUT in a db-connected REST service created via Apigility.
<?php
// Assume the controller service name is Api\V1\Rest\Foo\Controller.
// Do this in your Api\Module class:
public function onBootstrap($e)
{
$app = $e->getApplication();
$events = $app->getEventManager();
$sharedEvents = $events->getSharedManager();
$sharedEvents->attach('Api\V1\Rest\Foo\Controller', 'update.post', array($this, 'onUpdatePost'));
}
/**
* @param \ZF\Rest\ResourceEvent $e
*/
public function onUpdatePost($e)
{
$halResource = $e->getParam('resource');
$entity =& $halResource->resource;
// manipulate $entity at this point to the structure you want
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment