[Maypole] ala VIEW continued ?
raptor@tvskat.net
raptor@tvskat.net
Mon, 7 Jun 2004 13:37:51 +0300
hi,
I seem to have some success with it, but will post here so that u can check 'm I doing something stupid.. and how to continue after these first steps..
ok below is the code (only interesting lines):
package MaypoleICS;
#use base 'Apache::MVC';
use base 'CGI::Maypole';
use MaypoleICS::Stuff; <---------here is it
MaypoleICS->setup("dbi:SQLite:/path/to/db");
MaypoleICS->config->{uri_base} = "http://x.x.x.x/index.pl";
MaypoleICS->config->{rows_per_page} = 25;
MaypoleICS->config->{display_tables} = [qw(users addr stuff)];
...... etc.....
1;
then MaypoleICS::Stuff :
package MaypoleICS::Stuff;
use base qw(Maypole::Model::CDBI);
use Class::DBI::View qw(SubQuery);
MaypoleICS->setup("dbi:SQLite:/path/to/db");
MaypoleICS::Stuff->table('stuff');
MaypoleICS::Stuff->columns(All => qw(id name phone cx));
MaypoleICS::Stuff->setup_view(<<SQL);
SELECT users.id, users.name, addr.cx, addr.phone
FROM users, addr
WHERE users.id = addr.uid
SQL
1;
Now "list"-method is working, but if I try to go to the next page the links become something like this :
http://x.x.x.x/index.pl/(%20%20%20%20SELECT%20users.id,%20users.name,%20addr.cx,%20addr.phone%20%20%20%20FROM%20users,%20addr%20%20%20%20WHERE%20users.id%20=%20addr.uid)/list/?page=3
and ofcource "Internal server error" this probably is 'cause of the way Class::DBI::View is implemented, i'm not worring so much about it.... ('cause the usage of Class::DBI::VIew is only for temporary usage until i figure out how to do it right).
The thing that worries me is that i have to setup the DB again i.e. :
MaypoleICS->setup("dbi:SQLite:/path/to/db");
otherwise I have this :
Premature end of script headers: index.pl, referer: http://x.x.x.x/index.pl/stuff/list
Can't locate object method "db_Main" via package "MaypoleICS::Stuff" at /usr/lib/perl5/vendor_perl/5.8.2/Ima/DBI.pm line 386, <DATA> line 3077., referer: http://x.x.x.x/index.pl/stuff/list
Is there a way to overcome this...
tia