How to integrate Zendframework 2 library with Symfony 2?

How to integrate zendframework 2 library with my symfony 2 application? How to autoload and how to use it? I would like to use some classes.

+4
source share
2 answers

To integrate Zendframework 2 into Symfony 2, if you are using the standard Symfony distribution, add the following to the deps file at the root of your project:

[zf2] git=https://github.com/zendframework/zf2.git 

Now update the vendor libraries by running:

 php bin/vendors update 

If you are not using Symfony Standard Distribution, you will have to clone from github to the vendor folder.

Then add the Zend namespace to the app / autoload.php file so that these libraries are automatically loaded.

 $loader->registerNamespaces(array( ... 'Zend' => __DIR__ . '/../vendor/zf2/library', )); 

Then it is done. You can use the zendframework library. For example, I will show the use of the Zend \ Json class in a default Symfony 2 application. Open src / Acme / DemoBundle / Controller / DemoController.php and edit the indexAction method with the following code:

 use Zend\Json\Json; ... public function indexAction() { $data = array('zendframework2' => 'symfony2'); $encodedData = Json::encode($data); var_dump($encodedData); return array(); } 

In this example, I use the zendframework class to convert an array to json

+5
source

For Symfony 2.1, you need to add zendframework/zendframework under require in composer.json . If you want only a few packages, and not the entire library, you should add the URL to the Zend libraries under repositories , for example:

 "repositories": [ { "type": "composer", "url": "http://packages.zendframework.com/" } ], "require": { //... "zendframework/zend-log":"2.*", 
+3
source

All Articles