PHP code example of rimote / rimote-validation-bundle
1. Go to this page and download the library: Download rimote/rimote-validation-bundle library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
rimote / rimote-validation-bundle example snippets
// ...
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\JsonResponse;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Rimote\ValidationBundle\Validator\Exception\ErrorMessagesException;
use AppBundle\Entity\Cat;
/**
* @Route("/cats/", name="api_cats_create")
* @Method("POST")
* @ParamConverter("cat", converter="fos_rest.request_body")
*/
public function createAction(Request $request, Cat $cat)
{
// ...
$validator = $this->get('rimote.validator');
try {
$validator->validate($cat);
} catch (ErrorMessagesException $e) {
return new JsonResponse(['errors' => $e->getErrors()], 500);
}
// Run some code to for instance persist the cat in our database
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.