Using the Zend Framework in CakePHP

7 Jul

What do you get when you combine the powers of CakePHP 1.2.x and the Zend Framework?

No, not Captain Planet… something much more powerful – the ability to use the Google Data API PHP library! This is useful if you want to use Google Calendar or any of the other services supported by the data API.

Loading the Zend Framework isn’t as straightforward as App::Import(…), since Zend’s libraries assume that the Zend Framework folder is in your include path. To get around this simply:

  1. Drop the Zend Framework Library folder into your vendors folder
  2. Create a script in your Vendors folder called something like zend_include_path.php with the following statement:
    ini_set('include_path', ini_get('include_path').dirname(__FILE__));
    
  3. In your action, just do the following, replacing Gdata.php with whatever library you wish to load (i.e. Loader.php):
    function myAction() {
         App::import('Vendor', 'zend_include_path');
         App::import('Vendor', 'Zend_Gdata', true, false, 'Zend/Gdata.php');
    
         ...
    }
    

Voila! You should now be able to instantiate your loaded Zend Library Class and work with it normally.

  • Alexmbarton
    It's been a while since you posted here but i'm having an issue with it.

    I'm getting Warning: require_once(Zend/Gdata/App.php) failed to open stream.

    Fatal error: require_once() [function.require]: Failed opening required 'Zend/Gdata/App.php' (include_path='/Applications/MAMP/bin/php5/lib/php/Users/dir/Sites/student/app/vendors') in /Users/dir/Sites/student/app/vendors/Zend/Gdata.php on line 27

    Any ideas?

    Thanks

    AB
  • davidcm
    In fact, is better to use the PATH_SEPARATOR constant to determine the character to use. And there is no need to check if the include path ends with it or not, because an empty entry should no affect.

    ini_set('include_path', ini_get('include_path') . PATH_SEPARATOR . dirname(__FILE__));
  • JoshReedSchramm
    You good sir are a rockstar. Just found this post and it saved me a ton of headache. *tips hat*
  • Hey there, thanks for the advice. Works great, adjusting the include path on the fly like this.

    However, my include path was not ending in a semicolumn, so I had to adjust this in zend_include_path.php:

    ini_set(‘include_path’, ini_get(‘include_path’).';'.dirname(__FILE__));
  • Interesting - i guess the most extensible solution would be to check if
    there is a semicolon and add it if there is not - like your case.
    Thanks for sharing
blog comments powered by Disqus