Zend Framework on IIS 6
If you have tried to run Zend Framework on IIS 6 you may have run into a few problems. I will be covering how to get Zend Framework running once you have PHP installed. I am assuming that you have a clear understanding on how to set up Zend Framework and how it works.
1) ISAPI Redirect
You will need to install an ISAPI Redirect to simulate a .htaccess file on IIS.
There are a couple options you can use:
ISAPI_Rewrite ($99)
IIRF (Free)
2) Custom Controller
I always extend the Zend_Controller_Action, then all the controllers in the /application/controller directory will extend my custom controller not the Zend_Controller_Action. This is a good place to put $_GLOBALS in the Zend registry, set up database connections and site configuration options.
To get Zend Framework running with IIS 6 you will need to extend the Zend_Controller_Action, override the _redirect function and modify some server variables.
class Zoom_Controller_Action extends Zend_Controller_Action
{
public function _redirect($string)
{
if( !stristr($string, "http://") ) $string = "http://" . $_SERVER['SERVER_NAME'] . $string;
header("location: $string");
}
public function init()
{
$_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_REWRITE_URL'];
$_SERVER['QUERY_STRING'] = substr( $_SERVER['REQUEST_URI'] , strrpos( $_SERVER['REQUEST_URI'] , '?') + 1);
// LOOP THROUGH THE QUERYSTRING TO POPULATE THE $_REQUEST and $_GET arrays
$queryStringVariables = split('&', $_SERVER['QUERY_STRING']);
foreach( $queryStringVariables as $variable )
{
list($key, $value) = split('=', $variable);
$value = urldecode($value);
if( strpos($key, '[') )
{
$key = substr( $key, 0, strpos($key, '[') );
if( !is_array($_REQUEST[$key]) ) $_REQUEST[$key] = array();
$_REQUEST[$key][] = $value;
}
else
{
$_REQUEST[$key] = $value;
$_GET[$key] = $value;
}
}
}
}
3) Controllers
Now all the controllers in the /application/controller directory can extend the Zoom_Controller_Action. You must also call the parent::init() from all controllers extending the Zoom_Controller_Action to be sure to modify the server variables.
class ErrorController extends Zoom_Controller_Action
{
public function init()
{
parent::init();
}
}
Posted by Beau Durrant
















February 4th, 2010 at 2:32 am #Lee Pyotr
Great article. There’s a lot of good data here, though I did want to let you know something – I am running Fedora with the up-to-date beta of Firefox, and the layout of your blog is kind of bizarre for me. I can understand the articles, but the navigation doesn’t work so well.