2016-07-26 6 views
0

既存のアプリケーションには、追加のRESTfulエンドポイントが必要です。SymfonyとBasic RoutingとRESTの組み合わせ

次の設定でFOSRestBundleを追加しました。

fos_rest: 
    param_fetcher_listener: true 
    view: 
    mime_types: 
     json: ['application/json', 'application/json;version=1.0', 'application/json;version=1.1', 'application/json;version=1.2'] 
    view_response_listener: 'force' 
    formats: 
     xml: false 
     json: true 
    templating_formats: 
     html: false 
    format_listener: 
     rules: 
     - priorities: [json, xml] 
     - fallback_format: json 
    exception: 
     codes: 
     'Symfony\Component\Routing\Exception\ResourceNotFoundException': 404 
     'Doctrine\ORM\OptimisticLockException': HTTP_CONFLICT 
     messages: 
     'Symfony\Component\Routing\Exception\ResourceNotFoundException': true 
    allowed_methods_listener: true 
    access_denied_listener: 
     json: true 
    body_listener: true 
    routing_loader: 
     default_format: json 
     include_format: false 

REST要求が細かいですが、基本的なルーティングは今基本的に私はちょうど残り

答えて

1
で基本的なルーティングを組み合わせたい、次のエラー

This page contains the following errors: 

error on line 11 at column 92: EntityRef: expecting ';' 
Below is a rendering of the page up to the first error. 

を動作しません。

これを解決するには、特定のhtmlルートのフォーマットリスナーを無効にします(http://symfony.com/doc/current/bundles/FOSRestBundle/format_listener.html#disabling-the-format-listener-via-rules参照)

このように、config.ymlにフォーマットリスナーのルールを追加します。

format_listener: 
    rules: 
     - { path: '^/my-html-routes', stop: true } 
     - { path: '^/api', priorities: ['json', 'xml'], fallback_format: json } 
関連する問題