vendion has asked for the wisdom of the Perl Monks concerning the following question:
Per request of another Monk I am reposting my Catalyst question. I am new to Catalyst development and I am trying to create a View that displays the contents of a single table in my database, sort of like a "system users" page.
This is what I have in my controller:
sub base : Chained('/'): PathPart('admin'): CaptureArgs(0) { my ($self, $c) = @_; $c->stash( users_rs => $c->model('DB::Tech')); $c->log->debug('*** INSIDE BASE METHOD ***'); } sub list :Chained('base') :PathPart('list') :Args(0) { my ($self, $c) = @_; my ($users) = $c->model('DB::Tech')->search_rs; $c->stash( users => $users ); $c->stash(template => 'admin/list.tt2'); $c->log->debug("*** INSIDE LIST METHOD users = $users +***"); } sub create : Chained('base'): PathPart('create'): Args(0) { my ($self, $c) = @_; if(lc $c->req->method eq 'post') { # Retrieve the values fro mthe form my $params = $c->req->params; my $users_rs = $c->stash->{users_rs}; my ( $sec, $min, $hour, $mday, $mon, $year, $wday, $yd +ay, $isdst ) = localtime time; $year += 1900; my @month_abbr = qw( Jan Feb Mar Apr May Jun Jul Aug S +ep Oct Nov Dec ); my $date = "$year-$month_abbr[$mon]-$mday"; my $newuser = eval { $users_rs->create({ username => $params->{username}, password => $params->{password}, fname => $params->{fname}, lname => $params->{lname}, email => $params->{email}, phone => $params->{phone}, managementrating => '5', managementcomments => q[], date => $date, ismanagement => '0', }) }; if($@) { $c->log->debug( "Invalid email address in user creatio +n" ); $c->stash->{error_msg} = 'Invalid email addres +s in user creation'; return; } $Data::Dumper::Useperl = 1; } }
The create subroutine works and I am able to add new entries to my database, but the list doesn't display anything. Here is what I get from the Catalyst server:
[info] *** Request 1 (0.167/s) [19733] [Tue Mar 29 20:49:35 2011] *** + + + [debug] "GET" request for "admin/list" from "192.168.1.3" + + + [debug] Path is "/admin/list" + + + [debug] *** INSIDE BASE METHOD *** + + + [debug] *** INSIDE LIST METHOD users = 1 *** + + + [debug] Rendering template "admin/list.tt2" + + + [debug] Response Code: 200; Content-Type: text/html; charset=utf-8; Co +ntent-Length: 1546 + + [info] Request took 0.131545s (7.602/s)
Here is what my list.tt2 contains:
[% META title = 'System Users List' -%] <table> <tr><th>ID</th><th>firstname</th><th>lastname</th><th>email</th><th>ph +one</th><th>Management Rating</th><th>Comments</th><th>Date</th><th>A +dmin</th></tr> [% FOR tech IN users.all -%] <tr> <td>[% users.id %]</td> <td>[% users.firstname %]</td> <td>[% users.lastname %]</td> <td>[% users.phone %]</td> <td>[% users.email %]</td> <td>[% users.phone %]</td> <td>[% users.managementrating %]</td> <td>[% users.managementcomments %]</td> <td>[% users.date %]</td> <td>[% users.ismanagement %]</td> </tr> [% END -%] </table> <pre> Dump of the 'users' variable: [% Dumper.dump(users) %] </pre>
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Can't retrieve data in a catalyst controller
by Your Mother (Archbishop) on Mar 30, 2011 at 04:18 UTC | |
by vendion (Scribe) on Mar 30, 2011 at 19:16 UTC | |
by vendion (Scribe) on Apr 13, 2011 at 02:21 UTC | |
by ikegami (Patriarch) on Apr 13, 2011 at 04:43 UTC | |
by Your Mother (Archbishop) on Apr 13, 2011 at 13:46 UTC |