my $r = $self->routes;
[ somehow, extract the :customer holder into a variable $customer, then ]
controller => "$customer::boxs',action => 'get_list',
);
# / -> {controller => 'foo', action => 'bar'}
# /users -> {controller => 'users', action => 'bar'}
# /users/list -> {controller => 'users', action => 'list'}
$r->get('/:controller/:action')->to('foo#bar');Special stash values like controller and action can also be placeholders, which is very convenient especially during development, but should only be used very carefully, because every controller method becomes a potential route. All uppercase methods as well as those starting with an underscore are automatically hidden from the router and you can use "hide" in Mojolicious::Routes to add additional ones.
To know more, please definitely read the Tutorial and all of the Guides. But if you have any more questions, please don't hesitate to ask for Support.
--
You received this message because you are subscribed to the Google Groups "Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious...@googlegroups.com.
To post to this group, send email to mojol...@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.
Thanks Stefan.
So, trying a different tack, I was able to parse the url of a request with a 'before_depatch' hook, and figure out what Customer Class should be used, before routing happens.
Assuming the request url is /kwikemart/liquor/22, I figure out the customer name (kwikemart) like this:
sub startup {
my $self = shift; $self->hook( before_dispatch => sub {
my $c= shift;
$c->req->url->path =~ m#^/(\w+)/.+#;
$customer = $1; }}The question is, where to store this $customer, so I can use it to specify the correct route later? I still don't quite get how Mojo::Base Class work. Not sure how to correctly create custom attribute, that's local to each request, so it can be used within a $r->to() call.
#!/usr/bin/env perl
use Mojolicious::Lite;
get '/:customer' => sub {
my $c = shift;
$c->render(inline => 'Hello, <%= param "customer" %>!');
};
app->start;#!/usr/bin/env perl
use Mojolicious::Lite;
get '/:customer' => sub {
my $c = shift;
my $customer = $c->param('customer');
$c->render(inline => 'Hello, <%= $customer %>!', customer => $customer);
};
app->start;#!/usr/bin/env perl
use Mojolicious::Lite;
get '/:customer' => sub {
my $c = shift;
$c->render(inline => 'Hello, <%= $c->param("customer") %>!');
};
app->start;Thanks Stefan.
So, trying a different tack, I was able to parse the url of a request with a 'before_depatch' hook, and figure out what Customer Class should be used, before routing happens.
Assuming the request url is /kwikemart/liquor/22, I figure out the customer name (kwikemart) like this:
sub startup { my $self = shift;
$self->req->url->path =~ m#^/(\w+)/.+#; $customer = $1; }
The question is, where to store this $customer, so I can use it to specify the correct route later? I still don't quite get how Mojo::Base Class work. Not sure how to correctly create custom attribute, that's local to each request, so it can be used within a $r->to() call.
On Wednesday, January 2, 2019 at 4:34:20 AM UTC-6, hwmbo...@gmail.com wrote:
--