satooshi/symfony2contrib-http-foundation-extra-bundle
最新稳定版本:0.1.1
Composer 安装命令:
composer require satooshi/symfony2contrib-http-foundation-extra-bundle
包简介
Symfony2 contrib http foundation extra bundle
关键字:
README 文档
README
Install
See Packagist.
Annotation Usage
This bundle contains the following annotations.
- @File: force to download a file.
- @Json: create JsonResponse from controller result.
- Content-Type is
- application/json for json response
- text/javascript for jsonp response
- Content-Type is
# Acme/Bundle/Controller/SiteController.php use Contrib\Bundle\HttpFoundationExtraBundle\Configuration\File; use Contrib\Bundle\HttpFoundationExtraBundle\Configuration\Json; /** * @Route("/site") */ class SiteController { /** * @Route("/csv", name="site_csv") * @Method("GET") * @File(filename = "test.csv", charset = "Shift_JIS") */ public function csvAction() { $content = 'item1,item2'; return array( 'content' => $content, // read file in FileResponse and ignore content if this was set to controller result //'path' => './test.csv', ); } /** * @Route("/json", name="site_json") * @Method("GET") * @Json */ public function jsonAction() { // result response // {"prop1":"value1","prop2":"value2"} return array( 'prop1' => 'value1', 'prop2' => 'value2' ); } /** * @Route("/jsonp", name="site_jsonp") * @Method("GET") * @Json(callbackName = "jsoncallback") */ public function jsonpAction() { // request // /site/jsonp?jsoncallback=mycallback // response // mycallback({"prop1":"value1","prop2":"value2"}); return array( 'prop1' => 'value1', 'prop2' => 'value2' ); } }
@File parameters
- filename: required if "content" was set to controller result. optional if "path" was set. used for "Content-Disposition" HTTP header
- charset: optional charactor encoding. used for "Content-Type" HTTP header
- mimeType: optional mime type. default value is "application/octet-stream". used for "Content-Type" HTTP header
@Json parameters
- callbackName: optional callback request parameter name (default value: callback).
- serialize: optional boolean whether to use serializer (jms/serializer).
- serializeGroups: optional array to use serialize group.
todo
- avoid HTTP header conflict if it has already been set
- add supecific file type annotation support (@Plain, @Csv, @Pdf, @Zip, and so on)
- add rendering template functionality as the same as @Template
- add DependencyInjection/Cofiguration to support default parameter configuration
- add unit test
统计信息
- 总下载量: 32
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2013-01-21