2009年5月30日星期六

[fw-mvc] Redirect to Zend_Navigation_Page_Mvc object

Hello!

Wondering about best practices again…this morning, I ran into a use
case where, in my controller, I needed to redirect to a specific page,
and I already had access to a Zend_Navigation_Page_Mvc instance
containing all the necessary routing parameters. So far, I've found
one decent approach to this:

$this->_helper->Redirector->gotoUrlAndExit($page->getHref(),
array('prependBase' => false));

I found I had to add the "prependBase" option due to the way things
are handled in the redirector; try it without it and you'll see what I
mean. I don't think this was a bug by any means, but just something
that gave me a little headache for awhile :)

I was thinking, however, that it might be useful to have a couple more
methods in the redirect helper to support Zend_Navigation_Page objects
directly, like this:

$this->_helper->Redirector->gotoPageAndExit($page);

Lots cleaner, no need to remember the prependBase option, and doesn't
seem like it would take a lot of code. If everyone thinks this is a
good idea, I'd be happy to submit both an issue and a patch. Kind of
a small improvement, but I thought it might be nice; let me know what
you think!

Thanks!
Adam

没有评论: