[Catalyst] $c->res->redirect and $c->detach
jjn1056 at yahoo.com
Tue Sep 19 00:06:50 CEST 2006
--- Matt S Trout <dbix-class at trout.me.uk> wrote:
> John Napiorkowski wrote:
> > Hi,
> > I have a controller with some chained actions.
> One of
> > the actions (not an endpoint) will redirect given
> > certain value for the arguments. However I find
> > this doesn't stop the chain from completing. I
> > get a line about the redirect in the log, but the
> > endpoint in that chain still activates.
> > I find that this doesn't happen when I use
> > although in this circumstance detach is not the
> > use for me.
> > Has anyone run into this before and found a way
> > it?
> Calling $c->res->redirect never stops anything from
> completing, all it does is
> set the appropriate data on the response. $c->detach
> is the correct thing to
> do here.
> Perhaps you need to rephrase your question in terms
> of why you feel detach
> isn't ideal and how that interacts with the way your
> architecture is put together?
It is probably more a case of my not understanding the
best way to do this. I'm still a bit stuck in my old
way of putting these types of applications together.
Let me explain a little more what I am doing and
perhaps this is solvable with a more catalyst-think
I'm using chained actions as part of a wiki system.
Basically I have actions that descend down a url which
first finds a wiki (I have multiply wikis in the
system) and then a wiki page and then an action
associated, such as create, view or edit. Now when I
run the action associated with finding the page in the
database based on the page title what I'd like to do
is redirect to the create action when we don't find
that a page exists. I think this is the best action
for a wiki and what is expected (as long as you have
Now I'd like the URL to actually change to represent
that you are on an edit page, which is why the detach
doesn't do it for me. If this is really the best
thing to do I guess I can bend my head around it, but
I find in not so intuitive to have a give url show
both content or a form.
I find it easier to write the tests for this if I can
detect the redirect action.
Doing a $c->detach('/end') after the redirect was
suggested to me, although I find this can give an
error since my default end action looks for a template
which is this case doesn't exist.
Maybe I should do both a redirect and a detach?
I can show you some code for this if that would help
you understand my thinking, although it's in two
different modules (I'm using the :Chained('.') feature
to help organize the code and it works fantastically).
Let me know what you think. Thank you for your
feedback and suggestions. --john
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
More information about the Catalyst