How can I integrate zendframework 2 library with my Symfony 2 application? How to autoload and how to use it? I would like to use some classes.
To integrate Zendframework 2 into Symfony 2, If you're using the Symfony Standard 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 in vendor folder.
Next, add the Zend namespace to the app/autoload.php file so that these libraries can be autoloaded.
$loader->registerNamespaces(array(
...
'Zend' => __DIR__ . '/../vendor/zf2/library',
));
Then It's done, You can use zendframework library. For example I will show Zend\Json class usage in the default symfony 2 application. Open src/Acme/DemoBundle/Controller/DemoController.php and edit indexAction method the code like below:
use Zend\Json\Json;
...
public function indexAction()
{
$data = array('zendframework2' => 'symfony2');
$encodedData = Json::encode($data);
var_dump($encodedData);
return array();
}
In this example I am using a zendframework class to convert an array to json
For Symfony 2.1 you'll need to add zendframework/zendframework
under require
in composer.json
. If you only want a few packages and not the whole library, you should add the url to the Zend libraries under repositories
, like so:
"repositories": [
{
"type": "composer",
"url": "http://packages.zendframework.com/"
}
],
"require": {
//...
"zendframework/zend-log":"2.*",
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With