Internal redirect in other controller?

1,204 views
Skip to first unread message

Ilya Skorik (RU)

unread,
Jun 2, 2010, 4:55:56 AM6/2/10
to Mojolicious
How I can transfer control in other controller with some parametres?

For example, I want send the user from controller "Database::Connect"
in controller "Errors::Database" with parametre "$errors" in which the
error text. And to render error message from Errors::Database
controller.

How?

vti

unread,
Jun 2, 2010, 4:57:22 AM6/2/10
to mojol...@googlegroups.com
There is no internal redirect support in Mojolicious.

> --
> You received this message because you are subscribed to the Google Groups "Mojolicious" group.
> To post to this group, send email to mojol...@googlegroups.com.
> To unsubscribe from this group, send email to mojolicious...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/mojolicious?hl=en.
>

Ilya Skorik (RU)

unread,
Jun 2, 2010, 5:01:01 AM6/2/10
to Mojolicious
Can I use redirect_to for this? How?

vti

unread,
Jun 2, 2010, 5:02:47 AM6/2/10
to mojol...@googlegroups.com
redirect_to is for external redirection. It will send 302 response to the browser with a Location header pointing to the, hm, new location!

Ilya Skorik (RU)

unread,
Jun 2, 2010, 5:04:05 AM6/2/10
to Mojolicious
And I can transfer parametres with the redirect_to?

vti

unread,
Jun 2, 2010, 5:13:40 AM6/2/10
to mojol...@googlegroups.com
You can send parameters using query string, but that's probably not what you want.

More information about what those controller do would help more.

Mirko Westermeier

unread,
Jun 2, 2010, 5:17:25 AM6/2/10
to mojol...@googlegroups.com
Hi Ilya,

You wrote (quote repaired):

>>>>> How I can transfer control in other controller with some
>>>>> parametres?

>>>> There is no internal redirect support in Mojolicious.
>>


>>> Can I use redirect_to for this? How?
>>

>> redirect_to is for external redirection. It will send 302 response
>> to the browser with a Location header pointing to the, hm, new
>> location!

> And I can transfer parametres with the redirect_to?

To transfer parameters over an external redirect, you may want to use
the flash.

<http://github.com/kraih/mojo/blob/master/lib/MojoX/Session/Cookie/Controller.pm#L99
>

HTH
memowe

--
Schmeddingstrasse 123 g, 48149 Muenster, <http://www.memowe.de/>
E-Mail: <ma...@memowe.de>, OpenPGP-Key-ID: 0x730E195D
Key fingerprint: 55A8 9646 9B58 60AC B5BC 9661 FDD4 93C0 730E 195D
E-Mails von mir sind signiert. Unsignierte E-Mails sind nicht von mir.

PGP.sig

Dmitry Konstantinov

unread,
Jun 2, 2010, 5:27:01 AM6/2/10
to mojol...@googlegroups.com
But you can just call method of another controller and share params in stash:

package Database::Connect;
use Errors::Database;
sub foo {
  my $self = shift;
  # errors check
  return $self->Errors::Database::message if $self->stash('error');
  # safe code
}


2010/6/2 vti <viache...@gmail.com>

There is no internal redirect support in Mojolicious.


--
With best regards,
 Дмитрий

Ilya Skorik (RU)

unread,
Jun 2, 2010, 5:29:02 AM6/2/10
to Mojolicious
I have use this solution:

unless ($dbh) {
#$c->redirect_to('/errors/database/', error => $DBI::errstr );
$c->render(controller => 'errors', action => 'database', error=>
$DBI::errstr );
return;
}

But it is interesting to see an simple example how to make POST
recirect with parametres using internal controller/action names.

On Jun 2, 1:17 pm, Mirko Westermeier <m...@memowe.de> wrote:
> Hi Ilya,
>
> You wrote (quote repaired):
>
> >>>>> How I can transfer control in other controller with some  
> >>>>> parametres?
> >>>> There is no internal redirect support in Mojolicious.
>
> >>> Can I use redirect_to for this? How?
>
> >> redirect_to is for external redirection. It will send 302 response  
> >> to the browser with a Location header pointing to the, hm, new  
> >> location!
> > And I can transfer parametres with the redirect_to?
>
> To transfer parameters over an external redirect, you may want to use  
> the flash.
>
> <http://github.com/kraih/mojo/blob/master/lib/MojoX/Session/Cookie/Con...
>  >
>
> HTH
> memowe
>
> --
> Schmeddingstrasse 123 g, 48149 Muenster, <http://www.memowe.de/>
> E-Mail: <m...@memowe.de>, OpenPGP-Key-ID: 0x730E195D
> Key fingerprint: 55A8 9646 9B58 60AC B5BC  9661 FDD4 93C0 730E 195D
> E-Mails von mir sind signiert. Unsignierte E-Mails sind nicht von mir.
>
>  PGP.sig
> < 1KViewDownload

vti

unread,
Jun 2, 2010, 5:45:09 AM6/2/10
to mojol...@googlegroups.com
Of course you can. You can do many crazy things ;p

Sebastian Riedel

unread,
Jun 2, 2010, 9:16:50 AM6/2/10
to mojol...@googlegroups.com
Ok, since i'm always asking this question when the topic comes up in the irc channel i guess i should ask it here too.
Does anyone know a single sensible use case for internal redirects, something that isn't better solved with a bridge or external redirect?
Note that this question has never been answered, and just because you want to doesn't count. ;)
To me internal redirects are just very bad style since they break REST.

--
Sebastian Riedel
http://labs.kraih.com
http://mojolicious.org
http://twitter.com/kraih

Sebastian Riedel

unread,
Jun 2, 2010, 9:27:18 AM6/2/10
to mojol...@googlegroups.com
Btw. The flash can be used to hold (serializable) data between external redirects, as shown in the tutorial.

http://github.com/kraih/mojo/blob/master/lib/Mojolicious/Lite.pm#L525

Vick Khera

unread,
Jun 2, 2010, 11:20:27 AM6/2/10
to mojol...@googlegroups.com
On Wed, Jun 2, 2010 at 9:16 AM, Sebastian Riedel <kra...@googlemail.com> wrote:
> Ok, since i'm always asking this question when the topic comes up in the irc channel i guess i should ask it here too.
> Does anyone know a single sensible use case for internal redirects, something that isn't better solved with a bridge or external redirect?

In the application layer, which is where mojo works, no.

In mod_perl, the authentication layers of the request as it passes
thru apache can be intercepted, and at those points it is useful to
redirect to a different place, ie, display the login form. This is
the *only* situation in over 13 years of doing this that I can think
of.

Sebastian Riedel

unread,
Jun 2, 2010, 11:55:11 AM6/2/10
to mojol...@googlegroups.com
> In the application layer, which is where mojo works, no.
>
> In mod_perl, the authentication layers of the request as it passes
> thru apache can be intercepted, and at those points it is useful to
> redirect to a different place, ie, display the login form. This is
> the *only* situation in over 13 years of doing this that I can think
> of.

The big problem here is that it breaks REST.
Lets say the user enters via "/show/picture/23", your auth layer notices that the session expired and the user needs to login again.
In your example you would redirect internally to "/login", a whole different endpoint, REST broken.
IMO what should have happened in a modern clean app is a 302 response redirecting the user externally to "/login".

Roland Lammel

unread,
Jun 2, 2010, 1:02:10 PM6/2/10
to mojol...@googlegroups.com
Concerning the internal redirect stuff to login...

Especially also anoying for standard webapps, where suddenly a login for is presented at a whole lot of different URLs. This also confuses browser caching a lot and form input helpers that try to be smart and remember where you entered what.

Cheers

+rl

--
You received this message because you are subscribed to the Google Groups "Mojolicious" group.
To post to this group, send email to mojol...@googlegroups.com.
To unsubscribe from this group, send email to mojolicious...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/mojolicious?hl=en.




--
Roland Lammel
QuikIT - IT Lösungen - flexibel und schnell
Web: http://www.quikit.at
Email: in...@quikit.at

"Enjoy your job, make lots of money, work within the law. Choose any two."

Vick Khera

unread,
Jun 2, 2010, 2:37:21 PM6/2/10
to mojol...@googlegroups.com
On Wed, Jun 2, 2010 at 11:55 AM, Sebastian Riedel <kra...@googlemail.com> wrote:
> In your example you would redirect internally to "/login", a whole different endpoint, REST broken.
> IMO what should have happened in a modern clean app is a 302 response redirecting the user externally to "/login".

The mod_perl login modules are what I'd call "prehistoric".

I don't think I like that model now, and in fact we are migrating away
from that in our own services to external redirects to proper login
pages as you recommend too.

I *thought* I was bolstering your argument against internal redirects
but I guess I wasn't totally clear :-)

Ilya Skorik (RU)

unread,
Jun 3, 2010, 1:36:29 AM6/3/10
to Mojolicious
I have a sentence, to add in redirect_to obvious possibility to
transfer parametres. Something like redirect_to(url, query => {a => b,
c => d})
Reply all
Reply to author
Forward
0 new messages