-- Ryan Graciano <[EMAIL PROTECTED]> wrote
(on Tuesday, 17 July 2007, 03:00 PM -0400):
> I'm trying to implement a little routing in my bootstrap script (before the
> dispatcher starts).  Essentially, under very specific conditions, I need to
> alter the controller that is invoked.  I found
> Zend_Controller_Action_HelperBroker and the Redirector, but I can't seem to 
> get
> them to function outside of an Action Controller.  I've tried various
> combinations of code similar to this -
> 
> $redirector = Zend_Controller_Action_HelperBroker::getExistingHelper
> ('Redirector');
> $redirector->goto('index');
> 
> ...but nothing seems to work. I've looked through the docs, and all of the
> examples seem to function inside of a controller.  Is there an easy way to
> accomplish what I'm trying to do?

You've got three problems:

 * The redirector won't yet be instantiated, so using
   getExistingHelper() will not return the redirector object. Use
   getStaticHelper() instead.

 * The redirector actually sets headers in the response object instead
   of emitting them immediately. This means that you have to tell the
   response object to send the headers if you want to redirect
   immediately (usually this is done automatically for you as part of
   the dispatch() routine in the front controller).
 
 * However, most likely, the response object is not even yet
   initialized, and because no action controller is in play, the helper
   has no way to retrieve it.

Maybe try the following:

  class DummyController extends Zend_Controller_Action
  {
  }

  $request  = new Zend_Controller_Request_Http();
  $response = new Zend_Controller_Response_Http();
  $action   = new DummyController($request, $response, array());

  $redirector = 
Zend_Controller_Action_HelperBroker::getStaticHelper('Redirector');
  $redirector->setActionController($action);
  $redirector->goto('index');
  $response->sendHeaders();

However, honestly, it would probably be easier to simply call header()
yourself.

-- 
Matthew Weier O'Phinney
PHP Developer            | [EMAIL PROTECTED]
Zend - The PHP Company   | http://www.zend.com/

Reply via email to