PayPal - The safer, easier way to pay online!

PHP doctrine projects - 5 minutes starter guide

Create a project

First, prepare Maven and follow the preparation instructions.

Next, type the following Maven goal in your command line and execute it:

mvn archetype:generate \
-DarchetypeGroupId=org.phpmaven \
-DarchetypeArtifactId=php5-doctrine-archetype \
-DarchetypeVersion=2.0-SNAPSHOT \
-DgroupId=org.sample \
-DartifactId=my-app \

After some time maven will ask to confirm the parameters. The result will look like this:

	|-- pom.xml 
	`-- src 
		`-- main 
			 |-- php 
			 |  `-- bootstrap_doctrine.php
			 |  `-- bootstrap.php
			 |  `-- cli-config.php
			 |  `-- cli-tools.php
			 |  |-- MyApp
			 |  |    `-- Entities
			 |  |         `-- MyModel.php
			 |  `-- my-app.php
			 `-- resources
			    `-- config
			         `-- doctrine.ini
  • src/main/php/lib - contains the project source code
  • src/main/php/resources - contains the additional resources; all non-php files like yaml, xml, etc
  • src/test/php - contains the test source code
  • pom.xml The project's Project Object Model, or POM, looks like this:


<?xml version="1.0" encoding="UTF-8"?>


        <!-- doctrine version -->
        <!-- also needs to reflect the real root folder for your autoloading classes -->
        <!-- only use relative path from app root -->


    <name>PHP 5 Doctrine Project</name>
    <description>Simple PHP 5 doctrine project.</description>

                <!-- enable doctrine dev mode -->
                <!-- use maven supplied doctrine -->
                <!-- sqlite for dev, use relative path from app root for db file-->

                <!-- disable doctrine dev mode -->
                <!-- use pear supplied doctrine-->
                <!-- mysql for production -->

What have I just done?

What have I just done?

You have just executed the Maven goal archetype:generate and passed various parameters to that goal. The prefix archetype is the plugin containing the goal. This goal created a default project structure for your PHP project.

Build the project

Switch to your sample project directory

cd my-app

and run:

mvn package

The command line will print out various actions, ending with the following:

[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 6 seconds
[INFO] Finished at: Thu Jul 20 19:15:06 CDT 2008
[INFO] Final Memory: 3M/6M
[INFO] ------------------------------------------------------------------------			

Maven has created a phar package under the project's target folder.

What has Maven done?

"Maven for PHP" validates the PHP code with the php.exe, runs PHPUnit tests, and creates a phar for the web project.

Setup the database schema

Your project is almost ready to run now, all that is left is creating the database schema, switch to the unified app root

cd target/classes
. Now run
php cli-tools.php orm:schema-tool:create
The default profile is configured to use sqlite as database so no further configuration is needed. A sample configuration for mysql can be found in the production profile. To activate the profile when building the project use
mvn package -Pproduction

Run the app

We can now run the app with

php my-app.php


Go to the "Documentation" section.