-
Marijn Huizendveld authored
Usage ----- ```php <?php use Silex\Application; use Silex\Provider\SerializerServiceProvider; use Symfony\Component\HttpFoundation\Response; $app = new Application(); $app->register(new SerializerServiceProvider); // only accept content types supported by the serializer via the assert method. $app->get("/pages/{id}.{_format}", function ($id) use ($app) { // assume a page_repository service exists that returns Page objects. The // object returned has getters and setters exposing the state. $page = $app['page_repository']->find($id); $format = $app['request']->getFormat(); if (!$page instanceof Page) { $this->abort("No page found for id: $id"); } return new Response($app['serializer']->serialize($page, $format), 200, array( "Content-Type" => $app['request']->getMimeType($format) )); })->assert("_format", "xml|json") ->assert("id", "\d+"); ```
03bccc83
Name |
Last commit
|
Last update |
---|---|---|
.. | ||
doctrine.rst | ||
form.rst | ||
http_cache.rst | ||
index.rst | ||
monolog.rst | ||
security.rst | ||
serializer.rst | ||
session.rst | ||
swiftmailer.rst | ||
translation.rst | ||
twig.rst | ||
url_generator.rst | ||
validator.rst |