Create a new Zend Framework project with Maven integration

Folder structure

First, a new PHP Maven web project is generated using the PHP web project - 5 minute starter guide. In this web project, the typical Zend Framework project structure must be integrated:

      my-project 
      |-- pom.xml 
      `-- src 
      		`-- main 
	      		|-- php 
	      		|    `-- org 
	      		|         `-- sample
	     		|             |-- controllers 
	     		|             |-- forms 
	     		|             |-- layouts 
	     		|             |-- models 
	     		|              `-- views
	     		`-- webapp 
	     			|-- images 
	     			|-- styles 
	     			`-- index.php 
As you can see, integration includes the two typical Zend Framework basic folders called "application" and "public", which now are featured under the "php/org/sample" and "webapp" folders.

pom.xml

In a next step, the pom.xml of the current project is adjusted, meaning that its dependency is added to the Zend Framework:
 <dependencies> 
 			<dependency>
      			<groupId>com.zend</groupId>
      			<artifactId>zend-framework</artifactId>
      			<version>1.7.5</version> 
      		</dependency>
      	  </dependencies> 

Install

The following command in the command line then installs the project, downloads the Zend Framework and unzips it to the "my-project/target/phpinc" folder.
 mvn install 

Convert an existing Zend Framework project to Maven

Preparation

First, please work through the "Create a new Zend Framework project with Maven integration" tutorial, in order to be able to generate the correct folder structure as well as a pom.xml file.
Next, all of the "../application" paths in the index.php need to be adjusted (in our example this refers to "../php/org/sample").

php:validate and the Autoloader

If the application uses the Zend Autoloader, this might cause problems during the maven goal "php:validate".
To avoid these problems, we recommend to initialize the Autoloader in a separate PHP script that is saved to "src/main/php/org/sample/registerautoload.php":
      <?php 
      require_once "Zend/Loader.php";
      Zend_Loader::registerAutoload(); 
      ?> 
This file is then added to the pom.xml as "auto prepend":
 
     	<plugin>
	      <groupId>org.phpmaven</groupId>
	      <artifactId>maven-php-plugin</artifactId>
	      <extensions>true</extensions>
	      <version>1.0-BETA-2</version> 
	      <configuration>
	     	 <compileArgs> -d auto_prepend_file=registerautoload.php
	     	 </compileArgs> <ignoreValidate>false</ignoreValidate>
	      </configuration> 
      </plugin> 
Having done that, the Zend Autoloader can be initialized during "php:validate" and, under normal circumstances, no class loading problems should occur.