Page 1 of 1

newbie Zend Framework question [SOLVED]

Posted: Wed Apr 09, 2008 8:17 am
by georgeoc
Hi,

I'm having great fun getting to know the Zend Framework. I'm very happy with what it's offered me so far.

One question about Controllers & Routers. I need to check on every page that the app has been installed correctly. If Zend_Config can load the database configuration file, I will connect to the database and proceed as normal. But if not, I need to redirect to the install page.

I'm not sure how and where to do this. Is there a way I can issue a redirect from outside a controller, or before the Front Controller even starts? Would I put it in the bootstrap file? Or do I need to run the check in every single Action Controller?

Thanks!

Re: newbie Zend Framework question

Posted: Wed Apr 09, 2008 10:52 am
by Christopher
You could do that in your bootstrap or in a preFilter.

Re: newbie Zend Framework question

Posted: Wed Apr 09, 2008 11:49 am
by georgeoc
Thanks, but more specifically, how would I issue the redirect? I'm not sure which method call to use on which class/object.

Re: newbie Zend Framework question

Posted: Wed Apr 09, 2008 12:13 pm
by John Cartwright
I would probably use a plugin, which is added in your bootstrap with your front controller. Basically I avoid unnecessary HTTP redirects, so if we can silently reroute the request that that is preferred. I've modified some code I had written previously (although it's been awhile since I've dropped ZF completely so things may have changed)

Code: Select all

 
class Northern_Plugin_Installation extends Zend_Controller_Plugin_Abstract
{
   //change depending on what module/controller/action you want to specify as the installer
   protected $installmap = array('module' => 'install', 'controller' => 'install', 'action' => 'index');
 
   public function preDispatch(Zend_Controller_Request_Abstract $request)
   {
      if (APP_INSTALLED_CONDITION === FALSE) {
         $request->setModuleName($this->installmap['module']);
         $request->setControllerName($this->installmap['controller']);
         $request->setActionName($this->installmap['action']);
      }
   }
}

Re: newbie Zend Framework question

Posted: Wed Apr 09, 2008 12:31 pm
by georgeoc
Fantastic - that's exactly what I was looking for!

Thanks Jcart.