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!
newbie Zend Framework question [SOLVED]
Moderator: General Moderators
newbie Zend Framework question [SOLVED]
Last edited by georgeoc on Wed Apr 09, 2008 12:31 pm, edited 1 time in total.
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: newbie Zend Framework question
Thanks, but more specifically, how would I issue the redirect? I'm not sure which method call to use on which class/object.
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: newbie Zend Framework question
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
Fantastic - that's exactly what I was looking for!
Thanks Jcart.
Thanks Jcart.