in reply to Re: Need help working with a view in Catalyst
in thread Need help working with a view in Catalyst

Following your suggestion of going with the for the data from my controller still needs to be places in the stash correct? The way I am currently doing it in my Controller is:

$c->stash(users => [$c->model('DB::tech')->search_rs]);

and in my template I am calling it via

[% FOR tech IN users.all -%]

but yet it still is not displaying any data from my database. There is one row in the table that I am trying to work with currently

repairs=> select * from tech; + uniqid | id | firstname | lastname | email | phone | managementrating + | managementcomments | dat e | ismanagement + --------+----+-----------+----------+-------+-------+----------------- +-+--------------------+------- -----+-------------- + 0 | 99 | Admin | | | | 10 + | | 1999-0 1-01 | t + (1 row)

Replies are listed 'Best First'.
Re^3: Need help working with a view in Catalyst
by Your Mother (Archbishop) on Mar 23, 2011 at 04:49 UTC

    Close. You don't want to take an array reference. The result set is already a reference to an object. Just change that–

    $c->stash( users => $c->model('DB::tech')->search_rs );

    –and you should be good. You might want to look around for advice and techniques with chained controller methods too. They go very well with chained result sets and can make code terse while still being easy to read and follow.

      Thank you, I will do just that

        I still running into the issue, I went ahead and changed it over to Changed instead of being local. I also added a chained method to add an entry to the table with after testing works so I know it is not a database issue. Here is my updated code for my controller

        sub base :Chained('/') :PathPart('admin') :CaptureArgs(0) { my ($self, $c) = @_; $c->stash( users => $c->model('DB::Tech')); $c->log->debug('*** INSIDE BASE METHOD ***'); } sub list :Chained('base') :PathPart('list') :Args(0) { my ($self, $c) = @_; $c->stash( users => $c->model('DB::Tech')->search_rs ); $c->stash(template => 'admin/list.tt2'); } sub add :Chained('base') :PathPart('add') :Args(0) { my ($self, $c) = @_; $c->stash(template => 'admin/new.tt2'); } sub add_do :Chained('base') :PathPart('add_do') :Args(0) { my ($self, $c) = @_; # Retrieve the values fro mthe form my $username = $c->request->params->{username}; my $password = $c->request->params->{password}; my $fname = $c->request->params->{fname}; my $lname = $c->request->params->{lname}; my $email = $c->request->params->{email}; my $phone = $c->request->params->{phone}; my ( $sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isd +st ) = localtime time; $year += 1900; my @month_abbr = qw( Jan Feb Mar Apr May Jun Jul Aug Sep Oct N +ov Dec ); my $date = "$year-$month_abbr[$mon]-$mday"; # Create the tech my $user = $c->model('DB::Tech')->create({ id => $username, password => $password, firstname => $fname, lastname => $lname, email => $email, phone => $phone, managementrating => '5', managementcomments => q[], date => $date, ismanagement => '0', }); $Data::Dumper::Useperl = 1; $c->stash(users => $user, template => 'admin/create_done.tt2'); }

        If the add and add_do subs would have failed then I would know it was a problem with my Model or database but this is just odd