doujiao1814 2016-01-12 16:15
浏览 73

Symfony 2 - FOSRestBundle - CSV序列化程序的格式侦听器

Im trying to see if a url has .csv on the end and if it does I need to set the format to CSV.

So i have tried to set up a format listener and this is what i have done so far

I have added this to the config file framework section:

request:
    formats:
        csv: 'text/csv'

Then I have this in the fos_rest section

fos_rest:
routing_loader:
    default_format: json
view:
    view_response_listener: true
    mime_types: { 'csv': ['text/csv','text/plain'] }
    formats:
        csv: true
        json: true
serializer:
    groups: [ Default ]
    serialize_null: true
service:
    view_handler: my.rest.view.handler
exception:
    codes:
        'test\testBundle\Exception\InvalidPageException': 404
format_listener:
    enabled: true
    rules:
        - { path: '^/api', priorities: ['csv', 'json'], fallback_format: json, exception_fallback_format: json , prefer_extension: false }

now this kind of works as it does set the format to csv, my problem is that it sets the format to csv for every request and not just when the url has .csv at the end

can anyone advise what i am doing wrong or what i am missing?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥100 set_link_state
    • ¥15 虚幻5 UE美术毛发渲染
    • ¥15 CVRP 图论 物流运输优化
    • ¥15 Tableau online 嵌入ppt失败
    • ¥100 支付宝网页转账系统不识别账号
    • ¥15 基于单片机的靶位控制系统
    • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度