newbie Zend Framework question [SOLVED]

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
georgeoc
Forum Contributor
Posts: 166
Joined: Wed Aug 09, 2006 4:21 pm
Location: London, UK

newbie Zend Framework question [SOLVED]

Post 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!
Last edited by georgeoc on Wed Apr 09, 2008 12:31 pm, edited 1 time in total.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: newbie Zend Framework question

Post by Christopher »

You could do that in your bootstrap or in a preFilter.
(#10850)
georgeoc
Forum Contributor
Posts: 166
Joined: Wed Aug 09, 2006 4:21 pm
Location: London, UK

Re: newbie Zend Framework question

Post 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.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: newbie Zend Framework question

Post 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']);
      }
   }
}
georgeoc
Forum Contributor
Posts: 166
Joined: Wed Aug 09, 2006 4:21 pm
Location: London, UK

Re: newbie Zend Framework question

Post by georgeoc »

Fantastic - that's exactly what I was looking for!

Thanks Jcart.
Post Reply