[dancer-users] passing session user name from route sub to route sub

Naveed Massjouni naveed at vt.edu
Tue Aug 25 06:12:36 BST 2015

On Mon, Aug 24, 2015 at 9:51 PM, Richard Reina <gatorreina at gmail.com> wrote:

> When a user signs in I do this to send them to their page with log in.
>         # Logged in successfully
>         session username => $input_hash->{FName};
>         redirect '/userpage';
> However, I am wondering how I can pass the username from on sub to another
> sub call within my MyApp.pm. So that as a user bounces to another page I
> can do a database query for that user. For example, if the user goes to.
> get '/JobsView' => sub {
>     #query open jobs for the user
> }
> How do I get the username inside '/JobsView' so that I can use it for SQL
> queries?
> Thanks

You should be able to access it with the same session keyword:

    get '/JobsView' => sub {
        my $username = session 'username';
        #query open jobs for the user

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.preshweb.co.uk/pipermail/dancer-users/attachments/20150825/11cfc7a1/attachment.html>

More information about the dancer-users mailing list