-1

I call first time this route where I put in session 0 :

public function userCaptcha(){
    $_SESSION['isFacebookRegistration'] = 0;
}

After that I call another method which is executed 2 times by server :

 public function index()
 {
    $this->session = $_SESSION['isFacebookRegistration'];
    error_log(print_r($_SESSION['isFacebookRegistration'],true), 3, "/tmp/error.log");
    $_SESSION['isFacebookRegistration'] = 3;
    return $this->render('template/index.twig');
 }

The view is :

{{ dump(session) }}

In the console for $_SESSION['isFacebookRegistration'], I get : 0 3, In the view only 3. So the question is, It's possible to send in view value 0 and after that to modify the value of $_SESSION['isFacebookRegistration'] in 3 ? I repeat that index() method is call 2 times by server.

halfer
  • 19,824
  • 17
  • 99
  • 186
TanGio
  • 766
  • 2
  • 12
  • 34

1 Answers1

1

You need this? If I understand you correctly, coz my english is not well

private $flag = false;

public function index()
{
    $this->session = $_SESSION['isFacebookRegistration'];
    error_log(print_r($_SESSION['isFacebookRegistration'],true), 3, "/tmp/error.log");

    if ($this->flag) {
        $_SESSION['isFacebookRegistration'] = 3;
    } else {
        $this->flag = true;
    }

    return $this->render('template/index.twig');
}

Also you can pass an additional parameter (I think it will be better):

public function index($changeSessionValue = false)
{
    $this->session = $_SESSION['isFacebookRegistration'];
    error_log(print_r($_SESSION['isFacebookRegistration'],true), 3, "/tmp/error.log");

    if ($changeSessionValue) {
        $_SESSION['isFacebookRegistration'] = 3;
    }

    return $this->render('template/index.twig');
}
deniskoronets
  • 520
  • 3
  • 15
  • Not work, so when I acces route homepage, method index() is called 2 times. Now I want if I access first time homepage(method index() is called 2 times and the value from session need to be 0). If I access second time the route homepage (method index() is executed 2 times and value need to be 3) – TanGio Jul 28 '15 at 08:41
  • In your case I get only `0 0` – TanGio Jul 28 '15 at 08:42
  • `isSecondCall) { $_SESSION['isFacebookRegistration'] = 3; } else { $this->isSecondCall = true; } var_dump($_SESSION['isFacebookRegistration']); } } $a = new Test; $a->index(); $a->index();` Is works for me – deniskoronets Jul 28 '15 at 08:56