[Catalyst] Root.pm $c->detach() does not detach?

Luis Azevedo braceta at sapo.pt
Thu Apr 5 22:29:25 GMT 2007


Thanks Michael, Brian and Alexander.

The:

	$c->forward('login/index');
	return 0;

breaks up the chain correctly in the "auto" action!

Many thanks for your help! :)

Cheers,


Luís Azevedo

> Hi All,
>
> In Root.pm, "auto" action I am trying to break the execution of  
> chain of
> Actions.
>
> To be more exact, whenever I detect I loose connection to a socket  
> or cookie
> session, I want to redirect the user to a login action, not  
> rendering the
> action the user is calling.
>
> I know I can make a simple $c->res->redirect() but the problem is I  
> need to
> show a message in the login page telling the reason for the  
> "logout". Usually
> I am passing messages trough Stash. Redirecting to the Login page  
> needs to
> pass message somehow (through GET or POST, therefore not so  
> beautiful s).
>
> I have tried to detach the /login action,  in "auto" action from  
> Root.pm
> controller,  but it is not working and I don't know why. See the  
> actions
> chain:
> | /auto
> |  -> /login/index
> | /about/index
> | /end
>
> The user called the /about action.
>
> Can I break the chain somehow in Root.pm, "auto" action?
>
> Thanks in advance,
>
> -- 
> Luís Azevedo
>
>
>
>
>
> ------------------------------
>
> Message: 3
> Date: Tue, 3 Apr 2007 09:33:18 -0700
> From: Michael Reece <mreece at vinq.com>
> Subject: Re: [Catalyst] Root.pm $c->detach() does not detach?
> To: The elegant MVC web framework <catalyst at lists.rawmode.org>
> Message-ID: <58055936-C354-44B4-A394-E0F1D3B552A0 at vinq.com>
> Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed
>
>
> On Apr 3, 2007, at 9:18 AM, Luis Azevedo wrote:
>
>> Hi All,
>>
>> In Root.pm, "auto" action I am trying to break the execution of
>> chain of
>> Actions.
>>
>> To be more exact, whenever I detect I loose connection to a socket
>> or cookie
>> session, I want to redirect the user to a login action, not
>> rendering the
>> action the user is calling.
>>
>> I know I can make a simple $c->res->redirect() but the problem is I
>> need to
>> show a message in the login page telling the reason for the
>> "logout". Usually
>> I am passing messages trough Stash. Redirecting to the Login page
>> needs to
>> pass message somehow (through GET or POST, therefore not so
>> beautiful s).
>>
>
> see $c->flash method in perldoc Catalyst::Plugin::Session --
> "Think of it as a stash that lasts for longer than one request,
> letting you redirect instead of forward."
>
>
>> I have tried to detach the /login action,  in "auto" action from
>> Root.pm
>> controller,  but it is not working and I don't know why. See the
>> actions
>> chain:
>> | /auto
>> |  -> /login/index
>> | /about/index
>> | /end
>>
>> The user called the /about action.
>>
>> Can I break the chain somehow in Root.pm, "auto" action?
>
> have you tried avoiding detach and using { $c->forward('/login/
> index'); return 0; } ?
>
>
>
>
>
> ------------------------------
>
> Message: 4
> Date: Tue, 03 Apr 2007 11:50:14 -0500
> From: Brian Kirkbride <brian.kirkbride at deeperbydesign.com>
> Subject: Re: [Catalyst] Root.pm $c->detach() does not detach?
> To: The elegant MVC web framework <catalyst at lists.rawmode.org>
> Message-ID: <461285C6.4040702 at deeperbydesign.com>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>
> Luis Azevedo wrote:
>> Hi All,
>>
>> In Root.pm, "auto" action I am trying to break the execution of  
>> chain of
>> Actions.
>>
>> To be more exact, whenever I detect I loose connection to a socket  
>> or cookie
>> session, I want to redirect the user to a login action, not  
>> rendering the
>> action the user is calling.
>>
>> I know I can make a simple $c->res->redirect() but the problem is  
>> I need to
>> show a message in the login page telling the reason for the  
>> "logout". Usually
>> I am passing messages trough Stash. Redirecting to the Login page  
>> needs to
>> pass message somehow (through GET or POST, therefore not so  
>> beautiful s).
>>
>> I have tried to detach the /login action,  in "auto" action from  
>> Root.pm
>> controller,  but it is not working and I don't know why. See the  
>> actions
>> chain:
>> | /auto
>> |  -> /login/index
>> | /about/index
>> | /end
>>
>> The user called the /about action.
>>
>> Can I break the chain somehow in Root.pm, "auto" action?
>>
>> Thanks in advance,
>>
>
>
> I think what you want is something like
>
> 	if (!$logged_in) {
> 		$c->action(undef);
> 		$c->detach('/login');
> 	}
>
> Setting the action to undef in an auto sub will prevent the normal  
> dispatch of
> the request.
>
> Best,
> Brian
>
>
>
> ------------------------------
>
> Message: 5
> Date: Tue, 3 Apr 2007 18:54:01 +0200
> From: "Hartmaier Alexander" <Alexander.Hartmaier at t-systems.at>
> Subject: AW: [Catalyst] Root.pm $c->detach() does not detach?
> To: "The elegant MVC web framework" <catalyst at lists.rawmode.org>
> Message-ID:
> 	<2E192F962EB36A4EA92F89C3D24F8D64010E55B0 at MX1MAIL1.int.neonet.at>
> Content-Type: text/plain; charset="iso-8859-1"
>
> Hi!
>
> Detach doesn't work in sub auto, use forward instead an return 0  
> after the
> forward call.
>
> For example I have in my Root.pm:
>
>     # force login for all pages
>     unless ($c->user_exists) {
>         # detach doesn't work the way it should in auto
>         $c->forward('/login/login');
>         return 0;
>     }
>
> -Alex




More information about the Catalyst mailing list