Jason,
Take a look at the C::A docs and read up on
prerun_mode() & cgiapp_prerun()
If I understand what you're trying to do, you need something like:
sub setup
{
my $self = shift;
$self->run_modes
(
'search' => 'search',
'view' => 'view',
'show_tab1' => 'show_tab1',
'show_tab2' => 'show_tab2',
'show_tab3' => 'show_tab3',
);
}
sub cgiapp_prerun
{
my $self = shift;
my $request = $cgi->query;
if( $self->get_current_runmode() eq 'search' &&
$request->param('action') ne 'Search' )
{
my $tab = $request->param("tab") || "tab1";
$self->prerun_mode( show_' . $tab );
}
}
Hope that helps.
For more information on using cgiapp_prerun, cgiapp_postrun etc, take a look
at my tutorial on the CGI::App Wiki:
http://twiki.med.yale.edu/twiki2/bin/view/CGIapp/OrderOfOperations
---
Steve Comrie
----- Original Message -----
From: "Jason A. Crome" <crome@xxxxxxxxxxxxx>
To: <cgiapp@xxxxxxxxxxxxxxxxx>
Sent: Tuesday, February 10, 2004 4:24 PM
Subject: [cgiapp] Structuring my C::A
> Hello again,
>
> Thanks for the help I received on my earlier email :) Very much
> appreciated. I'm hoping again for some insight into a problem I'm having.
>
> My C::A has two modes: search and query. Each mode produces a web page
> consists of one or more "tabs". In search mode (for example), each tab
> collects some information from the user, then combines that data into a
> database query.
>
> The run modes in C::A rock :) But what I can't figure out is a good way
> (using C::A methods) to generate data for whatever tab a user selects. In
> my newbieness, I've only been able to determine a way using some if
> statements.
>
> Sample code looks like this:
>
> sub setup
> {
> my $self = shift;
>
> # Set the path to our templates
> $self->tmpl_path("$config{PATH_BASE}$config{PATH_TMPL}");
>
> # Declare our various run modes.
> $self->start_mode('search');
> $self->mode_param('mode');
> $self->run_modes('search' => 'search',
> 'view' => 'view');
> }
>
> sub search
> {
> my $self = shift;
> my $request = $self->query;
> my $page;
>
> # Did the user press search?
> if($request->param("action") eq "Search")
> {
> # detaint
> # build and execute query
> # show results page
> }
> # - OR -
> else
> {
> # Get and populate the selected tab
> my $tab = $request->param("tab") || "tab1";
>
> $page = show_tab1() if $tab eq "tab1";
> $page = show_tab2() if $tab eq "tab2";
> $page = show_tab3() if $tab eq "tab3";
> # Etc.
> }
>
> return $page;
> }
>
> I get some use out of C::A's run modes, but this doesn't seem as if it
makes
> the best use of what C::A has to offer. Problem is that I can't wrap my
> head around another way of doing it.
>
> Thanks for whatever advice can be offered!
>
> --------------------------------------------------
> Jason A. Crome
> Senior Software Engineer, DEVNET, Inc.
> E-Mail: crome@xxxxxxxxxxxxx
> http://www.devnetinc.com
>
>
>
> ---------------------------------------------------------------------
> Web Archive: http://www.mail-archive.com/cgiapp@xxxxxxxxxxxxxxxxx/
> http://marc.theaimsgroup.com/?l=cgiapp&r=1&w=2
> To unsubscribe, e-mail: cgiapp-unsubscribe@xxxxxxxxxxxxxxxxx
> For additional commands, e-mail: cgiapp-help@xxxxxxxxxxxxxxxxx
>
>
---------------------------------------------------------------------
Web Archive: http://www.mail-archive.com/cgiapp@xxxxxxxxxxxxxxxxx/
http://marc.theaimsgroup.com/?l=cgiapp&r=1&w=2
To unsubscribe, e-mail: cgiapp-unsubscribe@xxxxxxxxxxxxxxxxx
For additional commands, e-mail: cgiapp-help@xxxxxxxxxxxxxxxxx
|