Skip to content

Instantly share code, notes, and snippets.

@chanmix51
Created October 25, 2012 13:09
Show Gist options
  • Save chanmix51/3952450 to your computer and use it in GitHub Desktop.
Save chanmix51/3952450 to your computer and use it in GitHub Desktop.
How to validate POST data in Silex with Pomm
<?php application.php
// ...
$app->post('/tasks/new', function() use ($app) {
$task_map = $app['pomm.connection']
->getMapFor('\Taf\Task\Task');
$new_task = new Validation\NewTask($app['request']->request->get('new_task'));
$new_task->worker_id = $app['taf.session']->getWorkerId();
if (count($app['validator']->validate($new_task)) == 0)
{
$task = $task_map->createAndSaveObject((array) $new_task);
return $app->json(array('task' => $task->extract()), 201);
}
return new Response('Invalid or missing parameters.', 400);
})->before($check_token);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment