I am kicking off a new PHP project with the Zend Framework 2 (ZF2) and chose to use Doctrine as the persistence layer with ORM capabilities. Knowing that I need two Zend modules for Doctrine support, I've cloned the two modules (DoctrineModule and DoctrineORMModule) from GitHub to enable doctrine support in my ZF2 project. Oops, just installing those two Zend modules from GitHub do not make doctrine work! What am I doing wrong? Do I need a core Doctrine library from doctrine-project.org installed in addition to those two modules in order to make this work in ZF2? After a careful review of documentation, the preferred installation method was using "composer" not "git clone".
What is the composer? Composer is a dependency management tool for PHP, and it installs all dependent libraries that are required for a given project. So, as part of DoctrineModule installation, if core Doctrine/Common and Doctrine/DBAL are required, the dependency installer "composer" will automatically install them for me.
How do you define dependencies in composer? You'll either create/update a composer.json file that describes the projects' dependencies. This file is also created and/or updated by the composer when you install modules and libraries. A sample composer.json may look like below:
{ "require": { "doctrine/doctrine-module": "0.*", "doctrine/doctrine-orm-module": "0.*" } }
How do you install composer?
$ curl -sS https://getcomposer.org/installer | php
If you already have the composer.phar binary, and would like to update to the latest version you may run the self-update command. Running the command will replace your composer.phar binary file with the latest version. Some library updates may require you to update the composer as well.
$ php composer.phar self-update
Running the command above will check your PHP settings and download composer.phar, a Composer binary file into your local working directory.
How do you use composer?
If you have the composer.json file, the Composer will install dependent libraries for the project.
$ php composer.phar install or $ php composer.phar require doctrine/doctrine-module:0.* $ php composer.phar require doctrine/doctrine-orm-module:0.*
Share this post
Leave a comment
All comments are moderated. Spammy and bot submitted comments are deleted. Please submit the comments that are helpful to others, and we'll approve your comments. A comment that includes outbound link will only be approved if the content is relevant to the topic, and has some value to our readers.
Comments (0)
No comment