Change route in bridge

97 views
Skip to first unread message

Peter Bortchagovsky

unread,
Mar 13, 2013, 10:23:58 PM3/13/13
to mojol...@googlegroups.com
Hi all.
Why i can't define controller and action in bridge cb?

For example:
$r->bridge('/test')->to(cb => sub {
my $self = shift;
$self->stash(controller => 'foo');
$self->stash(action => 'bar');
return 1;
})->route->to;

I thought, that Foo::bar must be called. But i catch debug warning
> Template "foo/bar.html.ep" not found.
and nothing more happens.

Sebastian Riedel

unread,
Mar 13, 2013, 10:31:38 PM3/13/13
to mojol...@googlegroups.com
> Why i can't define controller and action in bridge cb?

Because we don't actually use the stash for dispatching, while there are a few ways to hack in the feature you want, there is no official API for it yet.

--
Sebastian Riedel
http://twitter.com/kraih
http://mojolicio.us

Peter Bortchagovsky

unread,
Mar 14, 2013, 10:02:00 AM3/14/13
to mojol...@googlegroups.com, kra...@googlemail.com
But how can I do a dynamic routes for application? If I do not want to hardcode routes and keep them into DB?
So, I want to find some place in app code, where I can take uri, find it in DB, fetch linked controller name and then dispatch to "$controller_name#process". How can I do it?

четверг, 14 марта 2013 г., 4:31:38 UTC+2 пользователь Sebastian Riedel написал:

Peter Bortchagovsky

unread,
Mar 18, 2013, 5:21:15 AM3/18/13
to mojol...@googlegroups.com, kra...@googlemail.com
Can anybody help me, please?

четверг, 14 марта 2013 г., 16:02:00 UTC+2 пользователь Peter Bortchagovsky написал:

John Berthels

unread,
Mar 18, 2013, 4:07:31 PM3/18/13
to mojol...@googlegroups.com
I'm not a mojo expert, but if you want to keep your routes in the db (not sure why?) you could always read them out of the db at startup and call ->route a few times?

But imho, the route mapping is part of the code and lives most sensibly in the code.

jb


--
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 http://groups.google.com/group/mojolicious?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Daniel Vinciguerra

unread,
Mar 18, 2013, 4:37:18 PM3/18/13
to mojolicious
I think that you can use a singleton class "out of mojo" and call/set values at execution time (like a config class)!

But I dont have tested it!


Daniel Vinciguerra

Web Solutions Architect and Co-Owner at Bivee
http://github.com/dvinciguerra

Peter Bortchagovsky

unread,
Mar 18, 2013, 6:25:55 PM3/18/13
to mojol...@googlegroups.com
I have a site with large and dynamically change contents tree, but with only several page types for tree items. I need to process and render every item by corresponding controller and template, which defined by "pagetype" field into DB record for this item. So, I think that the best way to create routes is something like this:
$r->bridge->to(cb => sub{
    $self = shift;
    $pagetype = get_pagetype_from_db( $self->tx->req->url->path->to_string );
    return "$pagetype#process"
})->route->to;
where $pagetype is controller name.
In my first question, I asked how can I use stash for the change of dispatch.
But, if I can't use it, maybe there is some other simple way to do this?
I do not want to create my self router because of Mojo has it. I think, that there must be a little hack or hook for this :)

понедельник, 18 марта 2013 г., 22:07:31 UTC+2 пользователь John Berthels написал:

Sebastian Riedel

unread,
Mar 18, 2013, 6:33:38 PM3/18/13
to mojol...@googlegroups.com
> But, if I can't use it, maybe there is some other simple way to do this?

I don't think there is.

> I do not want to create my self router because of Mojo has it. I think, that there must be a little hack or hook for this :)

The router has no hooks yet, they have been discussed a few times, but we never managed to come up with the right semantics and enough good use cases. (We don't add hooks that serve only one purpose)

Peter Bortchagovsky

unread,
Mar 18, 2013, 6:42:33 PM3/18/13
to mojol...@googlegroups.com
Thank you. I'll try to find yet another way to solve my problem :)


2013/3/19 Sebastian Riedel <kra...@googlemail.com>
--
You received this message because you are subscribed to a topic in the Google Groups "Mojolicious" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mojolicious/1RqcSNVucYU/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to mojolicious...@googlegroups.com.

sri

unread,
Mar 18, 2013, 7:12:48 PM3/18/13
to Mojolicious
Personally, i don't think dispatching dynamically based on data stored
in a database makes much sense, after all controllers and actions are
not dynamic either. I'd rather keep a bunch of basic routes in the
application and make the whole thing path based, with a
before_dispatch hook rewriting $self->req->url->path with whatever
rules you have stored in the database.

--
sebastian
Reply all
Reply to author
Forward
0 new messages