The Slim Framework support forum has moved to This Tender forum is no longer maintained or monitored.

How do i set and retreive a session form SLIM using the Slim_Middleware_SessionCookie

hans's Avatar


10 Apr, 2012 09:44 AM


How do i set and retreive a session form SLIM using the Slim_Middleware_SessionCookie?

I have added the $app->add('Slim_Middleware_SessionCookie'); before the $app->run();

It's not just setting: $_SESSION['test'] = "test";

And retreiveing:
if(isset($_SESSION['test'])) {

    $test = $_SESSION['test'];
} else {
    $test = "to bad";
  1. Support Staff 1 Posted by Josh Lockhart on 10 Apr, 2012 12:26 PM

    Josh Lockhart's Avatar

    The SessionCookie middleware is designed to be completely transparent. I prefer to add middleware immediately after I construct the Slim app. Then, in your route callables, use the $_SESSION superglobal as you normally would.

    Obviously, make sure your HTTP client supports cookies and that you have the libmcrypt extension installed.


  2. 2 Posted by hans on 10 Apr, 2012 12:42 PM

    hans's Avatar

    I use the $app->setEncryptedCookie with succes.

    I could use these cookies to put my pagination and sort preferences, but a session would be simpler.

    In the above example i put the write session in one route and the call in an other route. When i read your comment this should work right? But it doesn't ;-(

    What am i doing wrong?

  3. Support Staff 3 Posted by Josh Lockhart on 10 Apr, 2012 12:52 PM

    Josh Lockhart's Avatar

    It should work fine. Make sure you're using the latest develop or release-1.6.0 branch. If it still fails for you, please create a simple app that demonstrates the issue and post a gist of it so I can review your code.

  4. 4 Posted by hans on 10 Apr, 2012 02:41 PM

    hans's Avatar

    I get an error when i replace 1.5.2 with 1.6.

    Cant find Slim_View from TwigView.php line 41.

    I put the Slim framework under my app/libs folder outside the public_html root

  5. Support Staff 5 Posted by Andrew Smith on 01 Aug, 2012 12:52 PM

    Andrew Smith's Avatar

    The Slim_View issue should now be fixed.

  6. Andrew Smith closed this discussion on 01 Aug, 2012 12:53 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac