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:
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
source share