[Catalyst] Database contents not displayed after hitting page refresh

Emmanuel Quevillon tuco at pasteur.fr
Wed Sep 3 08:04:23 BST 2008


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

cranky wrote:
> Hi, I'm a newbie to catalyst. I have built a small app, similar to the one in
> catalyst manual (basic CRUD). I have a page wherein a <table> displays its
> contents after getting it from the database (SQLite3), the problem is, it
> doesn't display the contents after I refresh the page.
> 
> I'm using TT2 for html, here it is:
>  
> ------------------------------------------------------
> <table>
> [% WHILE (item = data.next) %]
> 	<tr>	
> 		<td> [% item.function | html %] </td>
> 		<td> [% item.testdate | html %] </td>
> 		<td> [% item.tester | html %] </td>
> 		<td> [% item.qalead | html %]</td>
> 		<td> [% item.nopassed | html %] </td>
> </table>
> -------------------------------------------------------
> 
> and the perl code looks like this:
> 
> -------------------------------------------------------
> sub ShowData : Local {
> 	my ($self, $c) = @_;
> 	my $data = $c->model('Ttrack::Ttrack');       
> 	$c->stash->{data} = $data;	
> 	$c->stash->{template} = 'ShowData.tt2';
> }
> -------------------------------------------------------
> 
> I generated the modules required under 'Model' by this command: 
> 
> C:\formdata\> perl script\formdata_create.pl model Ttrack DBIC::Schema
> formdata::Schema::Ttrack create=static dbi:SQLite:database
> 
> Where am I doing wrong?
> 

Hi 'cranky',

You need to perform a search in your 'ShowData' function to get data
returned by the Resultset of your model 'Ttrack::Ttrack'.
At this time, $data is only a resultset object without any data in it.
Replace :

my $data = $c->model('Ttrack::Ttrack');

with

my $data = $c->model('Ttrack::Ttrack')->search();

This will return all the data contained inside your table Ttrack.

Hope this will help.

Regards

Emmanuel


- --
- -------------------------
Emmanuel Quevillon
Biological Software and Databases Group
Institut Pasteur
+33 1 44 38 95 98
tuco at_ pasteur dot fr
- -------------------------
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFIvjb35ox+AMIKvTIRAhYfAKCDIRe8iSvmfVCDxhqDQ6jIDvB1rACeK6pQ
K02JPJ6tRrarACA+k+fHIAk=
=NaFY
-----END PGP SIGNATURE-----



More information about the Catalyst mailing list