|
From: Chris M. <Chr...@te...> - 2002-08-22 13:50:48
|
Thank you, that helps!
I have a new question - from reading the SPOPS::DBI module docs, it seems to
me that an object is meant to be sync'd with the database after a save, but
I can't seem to make that work - I have this code in a test class on my
server:
sub dbtry {
my $class = shift;
my $p = shift;
my $R = OpenInteract::Request->instance;
my $params = { main_script => '/Test', error_msg => $p->{error_msg} };
my $test = $R->test->new();
$test->{data} = "test data";
$test->save({skip_security => 1});
$params->{testval} = $test->{test_id};
return $R->template->handler( {}, $params, { db => 'test', package =>
'Test' } );
}
and this spops.perl:
$data = {
'test' => {
'object_name' => 'Test',
'no_update' => [
'test_id'
],
'isa' => [
'OpenInteract::SPOPS::DBI',
'SPOPS::Secure',
'SPOPS::DBI::MySQL',
'SPOPS::DBI'
],
'class' => 'portal::Test',
'no_insert' => [
'test_id'
],
'id_field' => 'test_id',
'base_table' => 'test',
'field' => [
'test_id',
'data'
],
'sql_defaults' => [
'test_id'
]
},
}
Note that I am using the database auto increment for the id field, not the
OpenInteract one. Anyway, I don't get anything back when I ask for the ID.
Can anyone help?
Thanks,
Chris
-----Original Message-----
From: Chris Winters [mailto:ch...@cw...]
Sent: August 22, 2002 7:36 AM
To: Chris McDaniel
Cc: 'ope...@li...'
Subject: Re: [Openinteract-help] question about $class and $p -
On Thu, 2002-08-22 at 00:03, Chris McDaniel wrote:
> Maybe I'm just revealing my own ignorance here, but can anyone tell me
about
> what is in $class and $p?
>
> as in:
> sub handler {
> my $class = shift;
> my $p = shift;
> my $R = OpenInteract::Request->instance;
> ...
> }
>
> Thanks, and sorry if this is a dumb question.
It's not. If I picked a more descriptive variable name it might be
easier :-)
Second item first: $p is a hashref of parameters. What is in there
depends on how things are setup. If you use 'GenericHandler' as a parent
(described below), you'll have some security settings in there.
Otherwise, it depends on how you're called. Handlers dealing with a
single object frequently look there first to find the object and/or ID
to act on, like:
my $news = $p->{news};
unless ( $news ) {
my $news_id = $p->{news_id} || $R->apache->param( 'news_id' );
$news = ( $news_id ) ? $R->news->fetch( $news_id )
: $R->news->new();
}
$class is the class of your handler. All handler methods are class
methods, so the class is always the first argument. This is useful for
inheritance -- many times you may want a top-level 'handler' method to
deal with some generic setup stuff but generate the content from a
specific class. So in OI you might have:
URL: /News/show/
Action: 'news' => { class => 'MySite::Handler::News' }
OpenInteract::Handler::GenericHandler
| - defines 'handler'
|
|---MySite::Handler::News
- defines 'show'
OI will call
MySite::Handler::News->handler(...)
which will call the inherited method from 'GenericHandler'. This checks
security, finds the task from the URL, etc. It then calls the content
method 'show' which is defined in your handler and which does the actual
work.
Hope that makes sense!
Chris
--
Chris Winters (ch...@cw...)
Building enterprise-capable snack solutions since 1988.
|