[Maypole] Help with Maypole::Model::CDBI::Plain
Simon Cozens
simon@simon-cozens.org
Sat, 17 Jul 2004 14:14:53 +0100
Jesse Sheidlower:
> I've been torturing Simon off-list about this, so I thought
> I'd give him a break and let someone else give it a shot.
> Has anyone managed to get this working?
For what it's worth, the code to Buscador is available at
http://cvs.simon-cozens.org/viewcvs.cgi/buscador/?cvsroot=Email and shows this
working.
> When I try to run this by going to http://localhost/sf/citation/list,
> I get the following error:
>
> [Sat Jul 17 08:54:00 2004] [error] Invalid CODE attribute:
> Exported at /usr/local/www/modules/sfDB/Citation.pm line 18
What this means is that your sfDB::Citation model doesn't correctly
inherit from one of the Maypole model classes. There are two ways to
ensure that it does. The first, which definitely works but is somewhat
unclean, is to explicitly make it to do:
package sfDB::Citation;
use base qw(sfDB::DBI Maypole::Model::CDBI::Plain);
The reason I don't like that is because you're repeating information about the
model class not just here in each of the table classes that you use, but also
in your driver class.
So there is the better way to do it, which is the one that Maypole
usually uses; this is to ensure that you set up your model class and call
"setup" *before* loading the individual table class. As part of "setup"
Maypole ensures that your table classes inherit from the correct model class.
So instead of
use sfDB::Citation;
sfDB->config->{model} = "...";
sfDB->setup(...)
you have something like
BEGIN {
sfDB->config->{model} = "...";
sfDB->setup(...)
}
use sfDB::Citation
Then sfDB::Citation will have inherited (somewhere down the chain) from
Maypole::Model::Base, by means of the "setup" call, and this means that
it will know about the attributes that Maypole uses.
I'm afraid I'm a bit tired of trying to make this particular example work
after several rounds of email about it :) so I just suggest you play with the
order of loading until it works. And don't forget that circular dependencies
in the code *can* screw up the way Perl loads things. (which is why I
mentioned it previously, I wasn't just bringing it up randomly. ;)
--
"Irrigation of the land with seawater desalinated by fusion power is ancient.
It's called 'rain'."
-- Michael McClary, in alt.fusion