in reply to Need help working with a view in Catalyst

If this is actually what you have–

[% FOREACH tech in tech -%]

–it should be (updated from what chromatic noticed)–

[% FOREACH tech IN users -%]

And FOR is more “perly.” I would probably also pass $c->model('DB::tech')->search_rs instead and then it becomes–

[% FOR tech IN users.all -%]

You have access to things like the pager and such passing the resultset around instead of a list of objects + deferred queries can sometimes be a win.

Replies are listed 'Best First'.
Re^2: Need help working with a view in Catalyst
by vendion (Scribe) on Mar 22, 2011 at 23:52 UTC

    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)

      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