|
From: Chris W. <ch...@cw...> - 2003-02-10 12:48:26
|
Chris McDaniel wrote:
> This is not my first package, but it is my first 'real' on for OI 1.54 (with
> DB and whatnot). I have 2 subs in my handler pm, one called "handler" and
> one called "cancel". Even when I post my form to /PackageName/Cancel,
> "handler" still gets called, and not cancel. I don't really know why this
> is happening. I've compared it to other packages and it looks OK, and there
> is nothing terribly out of the ordinary in the logs.
It's actually doing what it's supposed to. If you define 'handler'
that's the only method that will get called by the top-level
dispatcher. By defining it you're telling OI that you'll handle
whatever dispatching is necessary.
In most cases you want OI to handle this for you. To have OI handle
the dispatching (plus security checking, default action calling,
etc.), make your action a subclass of
OpenInteract::Handler::GenericDispatcher. Then rename 'handler' to
something else (e.g., 'display') and define the package variable
'default_method' to tell the dispatcher what method to call when
none is defined. So:
package My::Action:
use base qw( OpenInteract::Handler::GenericDispatcher );
$My::Action::default_method = 'display';
sub display {
# ... this will get called by default ...
}
sub cancel {
# ... this will get called when the user specifies
# 'cancel' in the URL ...
}
> Also, a quick question - what is the display bit in the spops.perl for? I
> thought action.perl took care of the display stuff?
It does, but 'display' in spops.perl makes it easy to ask the object
how to display itself and have one place for the information as
opposed to embedding URLs all over the place. (It's still probably
too much coupling, but it's not bad for now.)
You can get his information with the SPOPS 'object_description' method:
my $info = $spops_object->object_description;
print "My display URL: $info->{url}\n"
My edit URL: $info->{url_edit}\n",
My name: $info->{name} $info->{title}\n";
Chris
--
Chris Winters (ch...@cw...)
Building enterprise-capable snack solutions since 1988.
|