[Catalyst] How can we parse the path in catalyst
Vidya Sagar
vsagarkola at gmail.com
Wed Mar 1 13:59:54 CET 2006
Thank you very much Joe,
For your kind advice and the answer to my question.I didnt check
the code yet.But i was moved by your kind reply which was very
soft.Thankyou once
again.Take care Bye
On 3/1/06, Joe Landman <landman at scalableinformatics.com> wrote:
>
> Hi Vidya:
>
> Not going to look at your old code, thats for you to deal with.
>
> Here is the default regex that I use to handle my users controller,
> so that any URL of the form http://server/users/... gets mapped by
> default into this controller method.
>
> sub default : LocalRegex('(add|remove|account|list|search)') {
> my ( $self, $c ) = @_;
> my @stuff = @{$c->req->snippets};
> my ($rc,$q);
> my (@all);
>
> if (lc($stuff[0]) eq "doit")
> {
> $c->stash->{template}='admin/user.html';
> $c->stash->{mode}=$stuff[0];
> $c->forward('SICP::View::Mason');
>
> }
> else
> {
>
> @all = SICP::Model::DBIC::UserAccounts->search();
> push @{$c->stash->{list}}, at all;
>
> # set the template
> $c->stash->{template}='admin/user.html';
> $c->stash->{mode}=$stuff[0];
> $c->forward('SICP::View::Mason');
> }
> }
>
> Not the best code in the world, but what it does is take everything
> after the /users/ in the URL and map it into this controller for further
> processing.
>
> From here you can look at
>
> http://search.cpan.org/~mramberg/Catalyst-5.65/lib/Catalyst/Manual/Intro.pod#URL_Path_Handling
>
> and if you just want to munge it yourself, look at this
>
> http://search.cpan.org/~mramberg/Catalyst-5.65/lib/Catalyst/Request.pm#%24req-%3Epath
>
>
> specifically the $req->path. From this this you can slice and dice the
> path to your hearts content. Use the stash method to make your life
> easier in terms of temporary placement of information, and decide where
> you want do redirect the specific urls to. You can stash into specific
> templates for display. And you can call $c->forward as you require to
> hop over to a different controller, based in part on how you want to
> slice and dice your code.
>
> The rest is, unfortunately, up to you.
>
> Vidya Sagar wrote:
> > Hello all,
> >
> > how can i parse the path ie url in catalyst..my old code is:
> >
> > # parse path. it will translate old urls into new urls.
> > sub parse_path {
> >
> > my $self = shift;
> > # remove the trailing .html for any path other than starting
> > with /page/
> > $self->{path} =~ s/\.html$// if $self->{path} !~ /^page\//;
> >
> > $self->SUPER::parse_path(@_);
> >
> > # translate old paths into new paths
> > if($self->{path} =~ /cgi-bin\/store\/index.cgi/) {
> >
> > my $table = $self->{ar}->parms;
> >
> > if($table->get('page')) {
> > if($table->get('page') =~ /officeprods.cgi/) {
> > $self->{table} = 'categories';
> > $self->{action} = 'officeproducts';
> > }
> > elsif($table->get('page') =~ /arrow-faq.htm/) {
> > $self->{path} = 'page/arrow-faq.htm';
> > }
> > }
> > elsif($table->get('product') || $table->get('keywords'))
> {
> > # search product category
> > $self->{table} = 'product';
> > $self->{action} = 'find';
> > $table->set('keywords',
> > $table->get('keywords')." ".$table->get('product'));
> > }
> > else { # catch all condition send the user to home page
> > $self->{path} = 'frontpage';
> > }
> >
> > $table->unset('exact_match');
> > $table->unset('product');
> > $table->unset('cat_row');
> > $table->unset('cart_id');
> > $table->unset('search_stores');
> > $table->unset('page');
> > # dont remove the source parameter. it is needed to
> > decide on popup window
> > #$table->unset('source');
> > }
> > }
> >
> >
> > ------------------------------------------------------------------------
> >
> > _______________________________________________
> > Catalyst mailing list
> > Catalyst at lists.rawmode.org
> > http://lists.rawmode.org/mailman/listinfo/catalyst
>
> --
> Joseph Landman, Ph.D
> Founder and CEO
> Scalable Informatics LLC,
> email: landman at scalableinformatics.com
> web : http://www.scalableinformatics.com
> phone: +1 734 786 8423
> fax : +1 734 786 8452
> cell : +1 734 612 4615
>
> _______________________________________________
> Catalyst mailing list
> Catalyst at lists.rawmode.org
> http://lists.rawmode.org/mailman/listinfo/catalyst
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.rawmode.org/pipermail/catalyst/attachments/20060301/5201759b/attachment.htm
More information about the Catalyst
mailing list