test.ical.ly | getting the web by the balls



Using Zend Framework components in a Symfony2 project

Recently I wanted to use a part of the Zend Framework (v1) in my Symfony2 project.

After struggeling with the autoloading for a while and a little help from fellow developers on Twitter I found it actually to be quite easy.

First I move the ZF sources in /vendor/zf. I chose an unofficial github mirror for this.

Next I had to register a prefix (note: not registering a namespace!).

Now everything is almost working but there will be a lot of warnings and fatals because of all those require_once() in ZF.

Following the official ZF documentation I removed them.

Now you can just instanciate every ZF component you want.

Btw. thanks go out to Nils from PHP hates me! for the ZF/symfony logo that I stole for this post.


  • Pingback: Tweets that mention • Using Zend Framework components in a Symfony2 project | test.ical.ly -- Topsy.com()

  • Nils

    Ich bin halt doch der geilste Logo-Designer wo gibt!

  • Pingback: abcphp.com()

  • Pingback: Christian Schaefer’s Blog: Using Zend Framework components in a Symfony2 project | Development Blog With Code Updates : Developercast.com()

  • In order to solve the require_once requirement with Zend Framework you can use the set_include_path() function, as such:
    set_include_path(get_include_path() . PATH_SEPARATOR . $path);
    where $path is the directory that contains ZF library.

    Hope this helps.

  • @Andrei of course. but then you will have to do that on all systems your project is hosted on whereas the above option will work out of the box everywhere.

  • Alex Gilbert

    Thanks for this helpful post. I’ve been looking for a good tool to handle feed processing and I’m really eager to try out Zend_Feed with my Symfony2 project.

    I followed your instructions but I’m wondering if I made a mistake when trying to remove the require_once calls. Now anytime I attempt to use Zend_Loader::loadClass, I get an exception telling me the class doesn’t exist. Any thoughts? Thanks again!

  • @Alex with the above solution all classes are autoloaded automatically so you should not need to call Zend_Loader::loadClass() at all. Just use Zend_Feed.

  • Alex Gilbert

    Yes, but Zend_Feed::import() calls Zend_Uri::factory(), which then in turn calls Zend_Loader::loadClass().

  • @Alex ah right. I knew there were good reasons I never got into ZF too much.. ugly stuff. I guess you can override Zend_Loader and provide your own maybe..?

  • Jonathan

    FYI, on Windows, I could not get xargs working for some reason, but this is the command I ran through Git Bash shell:

    find . -name ‘*.php’ -print0 | xargs -0 sed –regexp-extended –in-place ‘s/(require_once)/\/\/ \1/g’

    Then, manually recopy the Loader.php and Application.php file back over the sedited ones.

  • I was having the same problem as Alex Gilbert. Symfony 2.0.1 here. My solution was to put the Zend library in vendor/zend-framework and instead of using the registerPrefixes method, i put the folder in the include path of PHP:

    At the end of the autoload file:

    $loader->registerPrefixFallbacks(explode(PATH_SEPARATOR, get_include_path()));

    In this case, don’t remove the include_once/require_once, as mentioned in the original post.

  • @Tito great solution thanks for sharing!

  • Warning with this “explode(PATH_SEPARATOR, get_include_path())” if you have stream (like phars) in the include path.

    See: http://bit.ly/ACCRED

    Solution from ZF Team: preg_split(‘#:(?!//)#’, get_include_path()).

  • Pingback: ZF library integration with Symfony2. « Codeperl's Knowledge Sharing System()

  • Isaac

    Thought I’d post this as it might help someone using Symfony 2.1. I wanted to use Zend Framework 1 with Symfony 2.1, and was hoping to use composer. ZF only publishes a composer for ZF2, not ZF1, but a bit of googling led to this solution which is working for me, hope it helps:

    { //other stuff “require”: { //other stuff “zendframework/zendframework1”: “1.11.*” }, //other stuff “repositories”: [ { “type”: “package”, “package”: { “name”: “zendframework/zendframework1”, “version”: “1.11”, “source”: { “url”: “http://framework.zend.com/svn/”, “type”: “svn”, “reference”: “framework/standard/trunk” }, “autoload”: { “classmap”: [“trunk/library/”] } } } ]}



Theme Design by devolux.nh2.me