> > On Apr 26, 8:11 am, Fabien Potencier <fabien.potenc...@symfony- > > project.com> wrote: > > >> return new Response(json_encode($data)); > > >> Fabien
Since for rendering templates you have to use this: return $this->render('FooBarBundle:Default:index.html.twig'); wouldn't be more "natural" implementing something like: $this- >render(json_encode($data), 'json'); ??? The second argument would set the content-type, to avoid to use $response->headers->set('Content-Type', 'application/json'); Javier On Apr 27, 1:34 am, Tim Nagel <t...@nagel.com.au> wrote: > There is no response object 'on the go'. The controller action's > responsibility is to create the response. > > t > > On Wed, Apr 27, 2011 at 07:59, stickaforkinme <sebdang...@gmail.com> wrote: > > Yeah worked that one out after posting on here... although prefered > > the old renderText method of sfActions in sf 1.x as this was a bit > > cleaner. :-) Creating a new response object just seems an odd way to > > do it as surly you already have a response object on the go. > > > On Apr 26, 8:11 am, Fabien Potencier <fabien.potenc...@symfony- > > project.com> wrote: > >> On 4/24/11 2:57 PM, stickaforkinme wrote: > > >> > I'm sure this is a really really stupid question but I can't seem to > >> > find a clean way to return a JSON object, i.e. by not calling a > >> > controller and just returning the result of json_encode. This was easy > >> > is Symfony 1.x but I have no idea how to do it in Symfony2. Any body > >> > know how to do this?? > > >> > I have a simple action function and just want to return a json object > >> > containing some data, that's all. > > >> In your action: > > >> return new Response(json_encode($data)); > > >> Fabien > > > -- > > If you want to report a vulnerability issue on symfony, please send it to > > security at symfony-project.com > > > You received this message because you are subscribed to the Google > > Groups "symfony users" group. > > To post to this group, send email to symfony-users@googlegroups.com > > To unsubscribe from this group, send email to > > symfony-users+unsubscr...@googlegroups.com > > For more options, visit this group at > >http://groups.google.com/group/symfony-users?hl=en -- If you want to report a vulnerability issue on symfony, please send it to security at symfony-project.com You received this message because you are subscribed to the Google Groups "symfony users" group. To post to this group, send email to symfony-users@googlegroups.com To unsubscribe from this group, send email to symfony-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/symfony-users?hl=en