php - How does the Symfony Response Object set http headers? -


i'm using sliex framework. had problem redirection when use \silex\application::redirectmethod. found when i'm trying redirect http-headers, instead of symfony "send" response seemed call __tostring method.

this curl output:

bash-4.2$ curl -v http://127.0.0.1:8082/ * connect() 127.0.0.1 port 8082 (#0) *   trying 127.0.0.1... * adding handle: conn: 0x1ea0970 * adding handle: send: 0 * adding handle: recv: 0 * curl_addhandletopipeline: length: 1 * - conn 0 (0x1ea0970) send_pipe: 1, recv_pipe: 0 * connected 127.0.0.1 (127.0.0.1) port 8082 (#0) > / http/1.1 > user-agent: curl/7.32.0 > host: 127.0.0.1:8082 > accept: */* >  < http/1.1 200 ok < date: sat, 20 sep 2014 08:02:52 gmt * server apache/2.4.10 (fedora) php/5.5.15 not blacklisted < server: apache/2.4.10 (fedora) php/5.5.15 < x-powered-by: php/5.5.15 < set-cookie: phpsessid=*****; path=/ < content-length: 116 < content-type: text/html; charset=utf-8 <  http/1.0 302 found cache-control: no-cache date:          sat, 20 sep 2014 08:02:52 gmt location:      /login  * connection #0 host 127.0.0.1 left intact 

i can't understand why echo http-headers.

update

my script this:

<?php class contorller {     public action( \silex\application $app ){        return $app->redirect('/login');     } } 

routing script:

<?php $core = new \silex\application; $core->get("/another/action", "\\controller::action") $core->match("/login","\\anothercontroller::login")->method('post|get'); 

the login action has no logic, , renders twig template.

calling $app->redirect() returns new redirectresponse object default status of 302.

the following taken directly symfony response object documentation

to set headers on symfony response object use headers->set method.

use \symfony\component\httpfoundation\redirectresponse;  class controller {     public function action( \silex\application $app ){          $response = new redirectresponse('/login', 302);          // headers public attribute responseheaderbag         $response->headers->set('content-type', 'text/plain');          return $response;     } } 

your code worked once typos in method names corrected (contorller changed controller).

class controller {     public function action( \silex\application $app ){        return $app->redirect('/login', 302);     } }  class anothercontroller {     public function login( \silex\application $app ){        return new response($app['twig']->render('blank.html.twig'));     } }  $app->get("/another/action", "\controller::action"); $app->match("/login","\anothercontroller::login")->method('post|get'); 

Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -

php - $params->set Array between square bracket -