I recently needed to use the Zend GData component in my Symfony2 project. It is very easy to setup, but there is one mistake that I suspect some other people might make as well.
First, add the Zend library to your vendor folder (e.g. vendor/Zend/library/Zend). As Zend does not use namespaces, you need to register the ‘Zend’ prefix instead. This can be done in the autoload.php file located in your app folder. Apparently Zend has some problems this way with ‘require_once’ statements, hence the modification of the include path (last line) :
// autoload.php
use Symfony\Component\ClassLoader\UniversalClassLoader;
// ... existing code
$loader->registerPrefixes(array(
'Twig_Extensions_' => __DIR__.'/../vendor/twig-extensions/lib',
'Twig_' => __DIR__.'/../vendor/twig/lib',
'Swift_' => __DIR__.'/../vendor/swiftmailer/lib/classes',
'Zend_' => __DIR__.'/../vendor/Zend/library',
));
$loader->register();
$loader->registerPrefixFallback(array(
__DIR__.'/../vendor/symfony/src/Symfony/Component/Locale/Resources/stubs',
));
set_include_path(__DIR__.'/../vendor/Zend/library'.PATH_SEPARATOR.get_include_path());
Now you are ready to use the Zend components. One mistake I made, I used the classes without a leading backslash, which does not work because the classes are in de default namespace. So, instead of using e.g.
$gdataCal = new Zend_Gdata_Calendar($client); // class not found error will be thrown
you need to add a backslash as such :
$gdataCal = new \Zend_Gdata_Calendar($client); // class is located in default namespace
Recent Comments