Session debugging in CakePHP
Often on IRC and the CakePHP google group, I hear people asking how to get values out of the Session or how to find out what is currently in the Session. Generally this is connected to AuthComponent, which is can be complicated component. However, some simple ‘crude’ PHP tactics can make the “whats’s in my session?” question very simple. Grab your layout file and add the following to it just above the <?php echo $cakeDebug; ?>
statement.
Show Plain Text
- <?php if (Configure::read('debug') > 1) :?>
- <div id="cakeSession" class="cakeSession">
- <h3>Session Info:</h3>
- <?php pr($_SESSION); ?>
- </div>
- <?php endif; ?>
This simple bit of code should be pretty self evident. And makes it easy to check what’s going on your Session. I like only outputting it at debug > 1 so when I turn down to one both my SQL logs and Session dumps disappear.
Mark,
something i do alot that is a little less “pretty” is
anonymous user on 8/12/08
Use the session object to avoid issues where CakePHP stores sessions elsewhere.
$this->Session->read()
MrYellow on 6/8/09