Roman  Kliuchko
Roman Kliuchko

Reputation: 499

FOSRestBundle annotations not working

FOSRestBundle annotations are not working for me somehow.

use FOS\RestBundle\Controller\Annotations as Rest;

// ...

/**
* @Rest\RequestParam(name="email")
*/
public function someAction(Request $request) 
{ 
   // some code
}

Here's my config:

fos_rest:
    param_fetcher_listener: true
    body_listener: true
    format_listener: false
    routing_loader:
       default_format: json
    view:
        view_response_listener: 'force'
        formats:
            xml: false
            json : true
        default_engine: none
        templating_formats:
            html: true
    access_denied_listener:
        json: true
    allowed_methods_listener: true

Requests to this action ignores annotation and just executes method's code. It seems that listener that should resolve these annotations is not running. Any suggestions?

Upvotes: 0

Views: 1583

Answers (1)

M. Foti
M. Foti

Reputation: 3182

change param_fetcher_listener: true to param_fetcher_listener: force and move code to:

use FOS\RestBundle\Request\ParamFetcher

/**
 * @Rest\RequestParam(name="email")
 */
public function someAction(ParamFetcher $paramFetcher) {

   $email = $paramFetcher->get('email');
} 

Note: Request parameter must be passed as POST

Upvotes: 2

Related Questions