Pragmatism in the real world

Zend Framework Tutorial: Version 1.1

It turns out that there are hardly any changes required to make the tutorial code compatible with version 0.2 of the Zend Framework! The only changes I had to make were to the index.php file.

The two changes needed were:

Zend_Config construction
You now create a Zend_Config_Ini directly:
$config = new Zend_Config_Ini('./application/config.ini', 'general'); is all that’s needed now!
Front Controller instantiation
For the original tutorial, I needed a special route for compatibility. This is now included by default in 0.2, so the work needed to be done is less. However, I’ve been playing with setting the rewrite base, and may have a better solution now. The new code for this bit is now:
$router = new Zend_Controller_RewriteRouter();
$baseUrl = substr($_SERVER['PHP_SELF'], 0,
strpos($_SERVER['PHP_SELF'], '/index.php'));
$router->setRewriteBase($baseUrl);
$controller = Zend_Controller_Front::getInstance();
$controller->setRouter($router);

I think it’s more likely to work on more configurations than my previous code. If anyone can see a security hole in this particular use of PHP_SELF, please shout though!

The new tutorial (version 1.1.0 – this time I’m prepared for point releases!) is available in the usual place. As always, comments and bug fixes are very welcome!

6 thoughts on “Zend Framework Tutorial: Version 1.1

  1. Hi,

    Mainly because I wasn't sure which version of Apache using which SAPIs generate SCRIPT_NAME/SCRIPT_FILENAME. Whereas PHP_SELF is generated by php, so I was pretty sure that it'd work everywhere.

    Regards,

    Rob…

  2. Hi,
    I have another possibility:

    $url = explode('index.php', $_SERVER['SCRIPT_NAME']);
    $baseUrl = $url[0];

    That works for my "domain.tld/index.php/controller/action/" URLs.

    Waldemar

  3. Waldemar,

    I would still need to find out if it's possible for $_SERVER['SCRIPT_NAME'] to ever not be present (or contain the wrong information.

    Regards,

    Rob…

Comments are closed.