Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$_SESSION global variable is not available when rendering $content #64

Open
scsmash3r opened this issue Jul 7, 2020 · 1 comment
Open

Comments

@scsmash3r
Copy link

scsmash3r commented Jul 7, 2020

How to reproduce:

$_SESSION['user_id'] = 'some_value';

$phpView = new PhpRenderer("path/to/templates", ["title" => "My App"]);
$phpView->setLayout("layout.php");

//...

$phpview->render($response, "hello.php", ["title" => "Hello - My App", "name" => "John"]);

In hello.php:

<?php var_dump($_SESSION); // Will not be set ?>
Hello <?=$name?>! Your id is: <?= $_SESSION['user_id'] ?>

In layout.php:

<?php var_dump($_SESSION); // Will be filled as intended ?>
<html><head><title><?=$title?></title></head><body><?=$content?></body></html>

So, in both hello.php and layout.php you will be able to get $title var. But, in hello.php global $_SESSION var will be empty.
Expected behavior would be leaving global variables intact.

@twogood
Copy link
Contributor

twogood commented Dec 28, 2020

If you need the session in whole or in part you should send it as a parameter to the render method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants