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,
$controller = Zend_Controller_Front::getInstance();
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”
Why not use SCRIPT_NAME or rather SCRIPT_FILENAME to find the rewrite base? Avoid using PHP_SELF at all…
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.
Well, I don't know which ones do either. I won't question your wisdom then ;).
I pinged the tutorial to http://www.planet-php.net via my own blog, honestly you should register your blog there: http://www.planet-php.net/submit/. Two days is too long to wait for my irregular blog checkup :).
Keep up the great work.
I have another possibility:
$url = explode('index.php', $_SERVER['SCRIPT_NAME']);
$baseUrl = $url;
That works for my "domain.tld/index.php/controller/action/" URLs.
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.