Pergunta

I'm trying to generate a url and set the _format variable to json. the .json part is never added to the route. setting to html or xml appends the format correctly.

The route from app/console router:debug,

api_1_get_page  GET      ANY    ANY  /api/page/{id}.{_format}                            

And my functional test code,

$this->getUrl('api_1_get_page', array('id' => $page->getId(), '_format' => 'json'));

when I dump this I get,

string(18) "/api/pages/1"

Whereas,

$this->getUrl('api_1_get_page', array('id' => $page->getId(), '_format' => 'html'));

returns string(18) "/api/pages/1.html"

I'm guessing there is a setting controlling this, I've tried setting every fos_rest config setting on and off and nothing is making a difference. This is also causing me issues when tests are checking the Location: header expecting .json.

Foi útil?

Solução

Have you set .json as the default format in your route?

If you're using FOSRestBundle look at routing_loader in the FOSRestBundle config

See: https://github.com/FriendsOfSymfony/FOSRestBundle/blob/master/Resources/doc/5-automatic-route-generation_single-restful-controller.md#routing

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top