php - Set a session variables using twig -


i have question. have route on site put in session variable this:

 public function usercaptcha(){     $_session['isfacebookregistration'] = 0;  } 

now have route witch render view :

public function index(){     $this->session = $_session;     return $this->render('template/index.twig'); } 

in index template :

 {{ dump(session.isfacebookregistration) }}  {% set session = session|merge({'isfacebookregistration' : 3}) %} 

i access first route : usercaptcha() 1 time route index() 2 times, need see first time 0 , second 3. see 0 2 times. can me please? idea show first time 0 rest 3. thx in advance

you cannot set php var on twig side. every time view reloaded, changes made variable lost. can try this:

public function usercaptcha(){     $_session['isfacebookregistration'] = 0; }  public function index(){     if (isset($_session['flag'])) {         $_session['isfacebookregistration'] = 3;     }     $_session['flag'] = true;     $this->session = $_session;     return $this->render('template/index.twig'); } 

this way, executing index() first time won't change isfacebookregistration value, set flag. next time, conditial true isfacebookregistration change.


Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -