On 11/22/05, Mark Stosberg <[EMAIL PROTECTED]> wrote:
> We do have CGI::Application::Dispatch already, but it has a smaller
> scope-- it doesn't currently handle turning URL bits into run mode
> parameters from what I can tell.
>
> Are others interested in this? Do you have favorite reference API for
> this, or a new one to suggest?
I am very interested in a generic system that handles this. Most of
my projects use CGI::Application::Dispatch, and in my latest work I
have implemented extra parameters in the PATH_INFO as well. I just
have some extra subroutines in my base class that do the work for me.
In my runmode things end up looking like this:
sub edit : Runmode {
my $self = shift;
my $tt_vars = shift || {};
my ( $category, $product_code )
= $self->fetch_path_params('category', 'product_code');
....
$self->tt_process($tt_vars);
}
The URL will look something like this:
http://example.com/store/manageproducts/edit/Widgets/abc123
Where store is the project name, manageproducts is the module, and
edit is the runmode. However, this URL is equally valid:
http://example.com/store/manageproducts/edit?category=Widgets&product_code=abc123
or even
http://example.com/store/manageproducts/edit/Widgets?product_code=abc123
The fetch_path_params works out the details of where the params come from.
I also have some methods that automatically build these URLs for me,
however, much of the code that drives it is still quite manual.
$self->url(
module => 'manageproducts',
rm => 'edit',
product_code => 'abc123',
category => 'Widgets',
extra_param => '123'
);
Which will generate
http://example.com/store/manageproducts/edit/Widgets/abc123?extra_param=123
'module' and 'rm' are optional, since the current values are
automatically re-used. Each module still needs to know what
parameters are used in each runmode, so that the URL can be built
correctly, so it is not very generalized. However, I find that most
runmodes require the same core parameters. a 'manageproducts' module
will need a product_code for pretty much every runmode.
The nice thing about the URL building methods is that I can use them
from within my templates:
[% FOREACH product in store.products %]
<a href="[% c.url( rm='edit' product_code=product.code ) %]">
Edit [% product.name %]
</a><br/>
[% END %]
My system is still a lot more work that I would like, so having
something like this built into a plugin would be a great addition!
Cheers,
Cees
---------------------------------------------------------------------
Web Archive: http://www.mail-archive.com/[email protected]/
http://marc.theaimsgroup.com/?l=cgiapp&r=1&w=2
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]