Created
October 25, 2012 13:09
-
-
Save chanmix51/3952450 to your computer and use it in GitHub Desktop.
How to validate POST data in Silex with Pomm
This file contains hidden or 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 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