Over the next few days, I’ll be covering how to set up your first Zend Framework application using PHP and MySQL.

First, some requirements. You should be comfortable on the command line or with your Subversion client. I’m writing from the point of view of someone who codes on a Linux or Mac machine using vim. You will need to have PHP 5 installed on your server — this will not work unless you do. Second, I would recommend getting a VPS from a host like Futurehosting — for $20/mo, you get root access to your own machine, you can host as many sites or servers and have as many domain names as you want, and you get 350gb a month in transfer — I don’t think I’ve used 1gb of transfer ever, and I do a ton of work with the server. I also Also, we’re going to assume you have access to a Subversion server. That’s just good practice, folks. Subversion hosts are very cheap — I usually use CVSDude.

Today we’re going to cover the folder structure, getting things into subversion, and locating the different files. Tuesday, we’ll cover the bootstrap and getting your index module and error module to show up. Wednesday, we’ll cover Zend_Db_Table_Abstract, Thursday we’ll cover Zend_Form, and Friday we’ll put it all together to get a user registration and login working.

Disclaimer: I’m by no means a whiz kid with Zend Framework. ZF is unique among frameworks in that it gives you a toolset but does not enforce any conventions. The conventions I’m giving here are *my* conventions and may have nothing to do with the way you want to code.

Let’s dive right in.

Set up a directory to import into SVN. Your directory structure at import will look something like:

/home/myusername/projectfolder
                    /branches
                    /tags
                    /trunk
                           /app
                           /html
                           /lib

Now, let’s import that into a Subversion repository that you’ve already created somewhere else. Type:

[kkatzke@server]$ cd ~/projectfolder
[kkatzke@server]$ svn import ./ \
> http://www.cvsdude.org/svn/myusername/myproject \
> -m "Initial Import"

(Those backslashes are included to indicate that the next line is also part of the command. I’m using them here because otherwise the text rides off into the sidebar.

Now delete the folders in your home directory that you created –
rm -rf /home/myusername/projectfolder.

Let’s head over to where you want to actually have your application live, or at least where you want to do your development work. This will usually be /var/www– or wherever your webroot is. (You could actually place any of these files anywhere on the system, or on another system — but we’re trying to keep this simple here.) You’ll run this checkout command: svn co http://cvsdude.org/svn/myusername/myproject/trunk . — and note that last period, it’s important. The results will look something like this:

A /app
A /html
A /lib

Now you’ve got a working copy of your three directories that will make up the application. The first thing we need to do here is to get a copy of the Zend Framework to work with. SVN makes it easy to do this. From the directory you checked out to (you should type ‘ls’ and see “app html lib”) Just run svn propedit lib, which should pop you into a blank text editor file. Type
Zend http://framework.zend.com/svn/framework/branch/release-1.5/library/Zend
and save and close the file. When you’re back at the command prompt, just type
svn update
and it will automatically pull in the Zend Framework into APP-ROOT/lib/Zend/ for you … although note that it specifically pulls in the lib/Zend folder, it does not pull in the incubator. That’s well outside of the scope of this beginner tutorial.

Last of all for today, you’ll need to add the rest of the directory structure for the application so that we can start with some code tomorrow. Here’s the way things should end up looking:

webroot/
        /app
              /config
              /controllers
              /forms
              /models
              /views
                      /scripts
                      /helpers
        /html
              /css
              /img
              /js
        /lib
              /Zend

When you’re done with all that, run svn add on all of the directories (use svn status to catch any you missed) and then run svn commit to save your changes to the repository. Congratulations! Tomorrow we’ll actually do something with all that work you did today.

No comments on ' Your First Zend Framework Application: Day One '

  1. No comments yet.

Leave a comment

name (req'd)

email (req'd)

website