I’ve written about using the Zend Framework within Symfony before but things have changed a bit in Symfony 1.1 so I wanted to post an update with a new Symfony 1.1 compatible approach to loading and using the library from within Symfony. The biggest change that has happened since my previous article is that the sfZendFrameworkBridge has been removed from Symfony. This is actually a Good Thing since, as you’ll see in a moment, there is now a more elegant approach to loading external libraries.
Most of the steps are the same as those outlined in the afore-linked article so you may want to read it before going further. The main difference will be how we get the Zend Framework files to autoload.
Getting the Library
This article assumes that you’ve placed the Zend Framework files in
<sf_project_root>/lib/vendor/Zend just as we did the last time around. Note though, that the Zend Framework subversion repository went through a bit of a restructure, so if you’re linking to
svn:externals you’ll want to use this updated format on
Linking the Library to Symfony
Now, to link the Zend Framework and allow auto-loading of class files, all you need to do is add a few lines to your application’s configuration class file. If your app is named
frontend then the file you’ll need to edit is located at
initialize() method to include the following:
public function initialize()
$sf_zend_lib_dir = sfConfig::get('sf_lib_dir').DIRECTORY_SEPARATOR.'vendor';
… and that’s it. Clear your cache (
./symfony cc from your project root) and you should be good to go. Creating an instance of a Zend Framework class is as easy as something like this:
Zend_Pdf will be auto-loaded for you.
The information in this article was gleaned from a post by Dustin Whittle and also one from Kris Wallsmith.