Last active
January 2, 2016 17:39
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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