Documentation » User

7. User Impersonation »

« 5. Two-step Validation (with Google Authenticator)

6. API

SonataUserBundle embeds Controllers to provide an API through FOSRestBundle, with its documentation provided by NelmioApiDocBundle.

6.1. Setup

If you wish to use it, you must first follow the installation instructions of both bundles:

Here’s the configuration we used, you may adapt it to your needs:

    param_fetcher_listener: true
    body_listener: true
    format_listener: true
        view_response_listener: force
        enabled: true
        validate: true
        map_exception_codes: true

    view: { annotations: false }
    router: { annotations: true }
    request: { converters: true }

    exception_controller: null

    error_controller: 'FOS\RestBundle\Controller\ExceptionController::showAction'

In order to activate the API’s, you’ll also need to add this to your routing:

    prefix: /api/user
    resource: "@SonataUserBundle/Resources/config/routing/standard_api_nelmio_v3.xml"

6.2. Serialization

We’re using JMSSerializationBundle's serialization groups to customize the inputs and outputs.

The taxonomy is as follows:

  • sonata_api_read is the group used to display entities
  • sonata_api_write is the group used for input entities (when used instead of forms)

If you wish to customize the outputted data, feel free to set up your own serialization options by configuring JMSSerializer with those groups.

Found a typo? Something is wrong in this documentation? Just fork and edit it!