sfZendPlugin Alternative to Installing the Zend Framework

If you're new here, you may want to subscribe to my RSS feed or follow me on Twitter. Thanks for visiting!

I often use the Zend Framework from within my Symfony applications and until recently, I’ve been using the sfZendPlugin to import and autoload the library. You’ll notice that this plugin has recently been axed leaving some people confused as to how to use the library in their projects.

Adding the Library

First, you’ll need to add the Zend Framework library. Since I like to link libraries via subversion, I’ll link the Zend Framework to my project’s lib/vendor directory. Open up a terminal to your symfony project’s root directory and type this:

 svn propedit svn:externals lib/vendor/

Note: You may have to create the vendor directory (and use svn add to add it to your repository) if you don’t already have it.

This will bring up a text editor where you can add a link to an external library via subversion. Type this in:

Zend http://framework.zend.com/svn/framework/tag/release-1.5.0PR/library/Zend

… and save and close the file and then do an svn up to pull in the library files. This will link lib/vendor/Zend to the 1.5.0 PR release of the Zend Framework. You can, of course, use another version if you prefer. Of course, you don’t have to link this via subversion. You can simply download and copy the Zend Framework into this folder for the same effect, but using subversion is my preferred method.

Linking the Library to Symfony

All you need to do now is activate symfony’s autoloading of the library files. Open up your application’s setting.yml file (mine is at apps/frontend/config/settings.yml) and add the appropriate settings. It should look something like this:

all:
  .settings:
    zend_lib_dir: %SF_ROOT_DIR%/lib/vendor
    autoloading_functions:
     - [sfZendFrameworkBridge, autoload]

Make sure to clear your symfony cache by using:

./symfony cc

That’s it! You should be able to use any of the Zend Framework classes from within symfony without using a require statement.

Edit: As per Gerald’s comment below, the zend_lib_dir path was listed as “zend_lib_dir: %SF_ROOT_DIR%/lib/vendor/Zend” but should not included the “Zend” folder name at the end as sfZendFrameworkBridge.class.php actually adds this automatically.

Update: These instructions only work with Symfony 1.0. I’ve written an updated article for using the Zend Framework with Symfony 1.1.


About this entry