New core helper: SessionHelper

Published on and tagged with cakephp  helper

In the latest version from trunk (1.1.7.3346), a new helper has been introduced: SessionHelper. Up to now it was rather cumbersome to work with session data in the view:

$this->controller->Session->read('User.name');

With the new SessionHelper the code snippet from above looks like:

$session->read('User.name');

The SessionHelper is automatically available in the view, i.e. you do not have to add it to the helpers array in the controller. It provides the following functions:

  • read($name = null)
  • check($name)
  • error()
  • flash($key = ‘flash’)
  • valid()

5 comments baked

  • Michael

    Short and simple – Nice addition!

  • Yuval

    Does PHP have custom variable attributes? In perl you can do this:

    my $counter : Session;
    print “This is visit number: ” . ++$counter;

    http://search.cpan.org/perldoc?Catalyst::Controller::BindLex

    I wonder if this feature could be ported

  • gwoo

    count should be done in the controller for something like this

  • New core helper: SessionHelper

    […] New core helper: SessionHelper: ”In the latest version from trunk (1.1.7.3346), a new helper has been introduced: SessionHelper. Up to now it was rather cumbersome to work with session data in the view: […]

  • sole

    hey that’s exactly what i needed :)
    i have just downloaded the nightly build, and it’s working nicely by the moment. Will report any bug if I find it (I was using the latest stable version until now but hey let’s try danger!!).

    Thanks for the useful tip :)

Bake a comment




(for code please use <code>...</code> [no escaping necessary])

© daniel hofstetter. Licensed under a Creative Commons License