Using Zend Studio with Zend Framework and Subversion

Published on December 31, 2009 by Andrew Sledge in PHP, Zend Framework

This tutorial guides you through setting up Zend Studio to work with Zend Framework and using a Subversion server with the IDE. This tutorial will also guide you though setting up a module-based ZF application.

Prerequisites: An installation of Zend Studio and Zend Server installed locally and subversion installed on a server.

This tutorial was written for a Linux box. Windows will be a little different with respect to path names and locations of stuff. There is an expectation that the reader is somewhat familiar with Zend Framework and has gone through the ZF Quickstart Tutorial at http://framework.zend.com/docs/quickstart. A familiarity of version control is also desired.

This is also a single-application setup. There is a potential to use a multiapplication setup (with one SVN server). The difference is that (aside from the obvious number of applications you maintain) a single app repository looks like

<APP NAME>
	trunk/
	branches/
		<APP NAME>1_2
	tags/

and a multiapp setup looks like

trunk/
	<APP NAME>1/
	<APP NAME>2/
branches/
	<APP NAME>1_1/
	<APP NAME>1_2/
	<APP NAME>2_1/
tags/
	<other stuff>

where <APP NAME> is arbitrary (as is your versioning nomenclature). You can use the tutorial below to set up a multiapplication config, but you will need to make a couple of changes that are listed at the very end.

A. Create a SVN repository

  1. Log into your SVN server
  2. Create a repository by running the following command:
    [sledge\@svnserv / ]$ cd ~
    [sledge\@svnserv ~ ]$ svnadmin create svn
  3. Launch Zend Studio (ZS)
  4. Open the SVN Repository Exploring perspective
  5. In the SVN Repositories (repo) pane, right click -> New -> Repo location
  6. In the URL enter:
    svn+ssh://svnserv/home/sledge/svn
    	- or -
    svn+ssh:///path/to/subversion/directory
  7. Click Finish
  8. Enter the SSH credentials necessary
  9. In the SVN Repo pane, expand the newly created repo
  10. Right click on ROOT -> New -> Project Structure
  11. Select Single project or multiple projects layout
  12. Give the project a meaningful name (I’ll use Project1) and enter “initializing project” in the comments area
  13. Go to Window -> Preferences -> Team -> SVN and click on the Repository tab
  14. Check the box Checkout trunk content instead of project itself


B. Create a ZF project

  1. Switch to the Zend Framework (ZF) perspective in ZS
  2. Right click in the PHP Explorer window -> New -> Zend Framework Project
  3. Give the project a meaningful name (Project1) and leave Create Project on a local server checked (remember where this location is)
  4. Click Finish
  5. Right click on the newly created project -> Team -> Share Project
  6. Select SVN and click Next
  7. Use the repo location that you created earlier, and click Next
  8. Select Advanced Mode
  9. Under Project Repo Layout, select Use single project layout. This will turn the future files location like svn+ssh://svnserv/home/sledge/svn/Project1/trunk
  10. Click Next then Finish
  11. Now ZS will commit the files to the SVN server. Enter “New upload” into the comments area (or something more meaningful) and click OK. If you use the command svnlook you can see the newly created file structure on the SVN server


C. Creating a modular ZF application

  1. If you created a ZF Project above, right click on the application folder in your project directory -> New -> Folder
  2. Ensure that the parent folder is correct, then type in “modules” into the folder name area then click OK
  3. Right click on that modules folder -> New -> Zend Framework Item
  4. Select Zend Module then next
  5. Ensure that the Source folder is correct (Project1/application/modules), and give the module a name (using “admin” here) and click Finish
  6. Drill down to that module’s controllers directory and right click on it -> New -> Zend Framework Item
  7. Select Zend Controller (Template based) then click Next
  8. Change the source folder to Project1/application/modules/admin/controllers and the file name to IndexController.php
  9. Click Next then Finish
  10. This opens your new controller file. You need to change the class name to the format ModuleName_FileName (no extension). So here it is Admin_IndexController
  11. Save the file.
  12. Open Project1/application/configs/application.ini
  13. Add the entry resources.frontController.moduleDirectory = APPLICATION_PATH "/modules" under the production section
  14. Within this same module (located at Project1/application/modules/admin) go into the views/scripts directory and create a folder (right click->New->folder) with a name of “index”
  15. Right click on this newly created directory -> New -> Zend Framework Item
  16. Select Zend View then click Next
  17. Ensure the source folder is the folder that you just created, and set the file name to “index.phtml”
  18. Click next then finish
  19. If you modify the index.phtml file you can test it out by entering <?php echo "hello world"; ?>
  20. To commit these changes to the svn server, right click on the project (Project1) -> Team -> Commit
  21. Add a worthwhile comment then click OK


D. Testing your ZF Application

  1. Since you installed Zend Server, you are able to test locally. You need to update the configuration file for Zend Server. Go to /usr/local/zend/apache2/conf and modify the DocumentRoot directive to be: DocumentRoot "/usr/local/zend/apache2/htdocs/<Project name>/public"
  2. Launch the Zend Server instance: sudo /usr/local/zend/bin/zendctl.sh start
  3. Surf to the page http://localhost:10088/. You should get a Welcome to Zend Framework Message.
  4. Surf to the page http://localhost:10088/admin (the module created above). You should get a “hello world” message.


APPENDIX: Using this tutorial with multiple applications on one SVN server

  1. Instead of using a single project layout as in A.11, use the monolithic layout
  2. Do not do A.14
  3. Use the Repository Location layout instead of single project layout in B.9.

Tags: ide php svn zend     Permalink   Bookmark and Share

Comments


No comments for this post.

Post a comment