php - Why is the controller executed twice (flashbag, redirectoroute)? -
i have 2 routes /alpha , /beta configured in yml. in alphaaction notice placed in flashbag , redirecttoroute occurs. in betaaction notice in flashbag read.
sometimes 2 notices when try /alpha in browser , 1 notice.
can explain happening, i'm doing wrong.
public function alphaaction() { $this->get('session')->getflashbag()->add("notice",mt_rand()); return $this->redirecttoroute("beta"); } public function betaaction() { $notices= $this->get('session')->getflashbag()->get('notice'); return new response(implode($notices,", ")); }
using add
method reproduce issues described. can fixed using set
method , not add
(or setflash
) method.
public function alphaaction() { $this->get('session')->getflashbag()->set("notice",mt_rand()); return $this->redirecttoroute("beta"); } public function betaaction() { $notices= $this->get('session')->getflashbag()->get('notice'); return new response(implode($notices,", ")); }
Comments
Post a Comment