Hello Monks.

I am working on a CRUD application using the Catalyst Framework and a Sqlite DB with a DBIx interface.

I have a controller with a list function like so:

sub list :Local { # Retrieve the usual Perl OO '$self' for this object. $c is the Ca +talyst # 'Context' that's used to 'glue together' the various components # that make up the application my ($self, $c) = @_; # Retrieve all of the book records as book model objects and store + in the # stash where they can be accessed by the TT template #$c->stash(resultset => [$c->model('DB::User')->all]); $c->stash (resultset => $c->model('DB::User')->all); use Data::Dumper; my $aref = $c->model('User'); $c->log->debug( Dumper $aref ); # Set the TT template to use. You will almost always want to do t +his # in your action methods (action methods respond to user input in # your controllers). $c->stash(template => 'main/list.tt'); }

Then I am using the following template:

[% cols = resultset.result_source.columns; FOREACH x IN cols; "<li>" +_ resultset.$x _ "</li>"; END %] [% # FOREACH row IN resultset %]Username: [% #row.username %]<br />[% +#END %] <table> <tr> <th>User Name</th> <th>Password</th> <th>Email</th> <th>FName</th> <th>LName</th> <th>Active</th> </tr> [% FOREACH row IN resultset %] <tr> <td>[% row.username %]</td> <td>[% row.password %]</td> <td>[% row.email_address %]</td> <td>[% row.first_name %]</td> <td>[% row.last_name %]</td> <td>[% row.active %]</td> </td> [% END %] </table>

the first line works, when I call:

$c->stash (resultset => $c->model('DB::User')->all);

but it only displays the first record. My table also only displays the first record in the table.

the first line doesn't work, and m y table displays all records when I call:

$c->stash (resultset => [$c->model('DB::User')->all]);

The problem is, what if I want to display the results of a different DB?
Seems that I should be able to use the same template... maybe I'm just not groking the model.

The tutorial says these are the same, the first two return undefined values:

# the long way my $rs = $c->model('FilmDB')->schema->resultset('Actor'); # using the shortcut method on the model object my $rs = $c->model('FilmDB')->resultset('Actor'); # using the generated class directly my $rs = $c->model('FilmDB::Actor');

Also, this returns a "can't find method" error:

my $dbic = $c->model('FilmDB')->schema; my $dbic = $c->model('DB::FilmDB')->schema;

I promise I have read the tutorials more than once.
I think the issue is probably something simple that I'm just misunderstanding.
Can someone please help me instead of just pointing me to the manuals?


In reply to Catalyst DBIx Help by PyrexKidd

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.