progress but still no joy (was Re: [Catalyst] still not sure if I have the hang of this ...)

Joe Landman landman at scalableinformatics.com
Wed Dec 28 07:46:27 CET 2005


Ok, started playing with DBIx::Class and DBIx::Class::Table, and a toy 
database.  Got a minimalistic test case going fine with that.  Now to 
make it work with Catalyst.

I did the "usual"

	catalyst.pl test
	cd test
	script/test_create.pl model Database DBIC dbi:SQLite:/root/test/db/test.db
	script/test_create.pl view Mason Mason

I added the Mason component root setup and other bits.  Then

	script/test_create.pl controller db

The db has a single table named testing, with a very simple structure:


	CREATE TABLE testing (
		id INTEGER PRIMARY KEY,
		name text,
		size text
	);

I added some simple data into it to make testing easier.

	sqlite> select * from testing;
	1|a|b
	2|c|d
	3|d|e

In the test/Model/Database/Testing.pm package, I added a pointer to the 
table and added the columns

	__PACKAGE__->table('testing');
	__PACKAGE__->add_columns(qw/id name size/);

I added a simple global list method to the db controller

	sub list : Global {
		use Data::Dumper;
		my ( $self, $c ) = @_;
   		my (@all);
  		 @all = test::Model::Database::Testing->search();
   		$c->forward( 'test::View::Mason');
   		$c->stash->{stuff}=Dumper(@all);
	}

Ok.   Now I am getting an error message of

	[Wed Dec 28 04:06:40 2005] [catalyst] [error] Couldn't render component 
"/list" - error was "could not find component for initial path '/list' 
(component roots are: '/root/test/root/static')
	Stack:
  	 [/usr/lib/perl5/site_perl/5.8.6/HTML/Mason/Request.pm:204]

for the http://dualcore:3000/list url.

I think this is a Mason error and not a Catalyst error.  I see the data 
in the stash at the end of the web page, and it is identical to what I 
generated with my DBIx::Class::Table bit.  I think I know how to fix it, 
but I am not completely sure.  Will experiment a bit more.

My question is, apart from a Mason error, is this the right general 
path?  Or I am doing something very wrong somewhere?   Basically we are 
taking a  Mason based application, and migrating it into Catalyst with a 
Mason view so we can do a saner job of extending/maintaining it.  Our 
old method of DB interaction was rather different, so I am trying to get 
on a fast (re)learning curve :).

Thanks again for the pointers and your patience.

BTW:  addcomment was not missing, I just didn't find it before posting. 
  I did find it later.  It was helpful as well.

Joe

Andreas Marienborg wrote:
> On 27. des. 2005, at 21.14, Joe Landman wrote:
> 
>> (I haven't used DBIx::Class and its ilk before so this might be a  
>> dumb question)
>>
>> I create a form.  I submit with that form.  I see the request go to  
>> the test server with the data.
>>
>> Now I want to take this data and stuff it into one of my model's  
>> tables.  I presume it is something like
>>
>>     __PACKAGE__->find_or_create({ key1 => $value1, key2 =>  $value2, 
>> ...} );
>>
> 
> You usually have to replace __PACKAGE__ with the actual model- package, 
> like MyApp::Model::Table->find_or_create
> 
> In a controller, __PACKAGE__ equals the package of the controller,  and 
> that controller, most likely, lacks a find_or_create method.
> 
>>
>> from the controller.  This seems wrong to me though, in that  wouldn't 
>> we want to go through the model?  I think I am missing  something 
>> fundamental here.
>>
>> Is there a really dumb/simple example out there for perusal which  
>> demonstrates taking data from a form and putting it into a database  
>> using Catalyst?  I can't seem to wrap my mind around the correct  
>> method, as I don't see an example of it.  I looked through the  Agave 
>> site, and it seems to be missing a few of the methods  (addcomment is 
>> pretty much what I want to see, but it doesn't  appear to be in the 
>> tree).
>>
> 
> Check out the BookDB example from dev.catalyst.perl.org
> 
> 
>> Thanks.
>>
>> Joe
>>
>>
>>
>> -- 
>> Joseph Landman, Ph.D
>> Founder and CEO
>> Scalable Informatics LLC,
>> email: landman at scalableinformatics.com
>> web  : http://www.scalableinformatics.com
>> phone: +1 734 786 8423
>> fax  : +1 734 786 8452
>> cell : +1 734 612 4615
>>
>>
>> _______________________________________________
>> Catalyst mailing list
>> Catalyst at lists.rawmode.org
>> http://lists.rawmode.org/mailman/listinfo/catalyst
> 
> 
> _______________________________________________
> Catalyst mailing list
> Catalyst at lists.rawmode.org
> http://lists.rawmode.org/mailman/listinfo/catalyst

-- 
Joseph Landman, Ph.D
Founder and CEO
Scalable Informatics LLC,
email: landman at scalableinformatics.com
web  : http://www.scalableinformatics.com
phone: +1 734 786 8423
fax  : +1 734 786 8452
cell : +1 734 612 4615



More information about the Catalyst mailing list