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:

$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()

4 Comments

  1. Michael
    Posted August 1, 2006 at 10:02 am | Permalink

    Short and simple – Nice addition!

  2. Yuval
    Posted August 1, 2006 at 12:34 pm | Permalink

    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

  3. gwoo
    Posted August 1, 2006 at 9:29 pm | Permalink

    count should be done in the controller for something like this

  4. Posted August 6, 2006 at 11:15 am | Permalink

    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 :)


One Trackback/Pingback

  1. […] 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: […]

%d bloggers like this: