So it is time to check out Zend Framework seeing how powerful everyone says it is. Setup is a bit annoying in comparison to other “funner” frameworks so I am going to document my findings as I learn. Here’s a guide to getting ZF working on your *nix dev box.

Setting up your environment

Using a SSH client such as Putty – connect to your web server and create a directory in your users home named “bin”

$ cd ~
$ mkdir bin
$ cd bin

Next we need to download a stable copy of Zend Framework via subversion using the following command :

$ svn checkout http://framework.zend.com/svn/framework/standard/branches/release-1.10/

If svn (Subversion) is not installed you can download via wget using the following command :

$ wget http://framework.zend.com/releases/ZendFramework-1.10.3/ZendFramework-1.10.3-minimal.tar.gz

Next we need to untar (decompress) the framework :

$ tar -zxvf ZendFramework-1.10.3-minimal.tar.gz

Rename the decompressed folder :

$ mv ZendFramework-1.10.3-minimal Zend

** Note if you used subversion to acquire Zend Framework – you probably have downloaded the release directory – use the command above replacing the first argument with the release directory name.

Move the scripts from the Zend/bin directory into the ~/bin directory; make them executable; rename zf.sh to just zf (for simplicity) :

$ mv Zend/bin/* .
$ chmod +x zf.sh
$ mv zf.sh zf

The next step is to add the zf script to the users include path, this allows us to use the zf command without having to specify the absolute path. Copy and paste the next 6 lines into your shell :

cat << EOF >> ~/.bashrc
if [ -d ~/bin ] ; then
PATH=~/bin:"\${PATH}"
fi
export PATH
EOF

You must now log out and back in to activate this path. Once you are logged back in you can test the zf command by typing :

$ zf show version

If you see “Zend Framework Version: 1.10.3″ you are ready to start your first project.

Creating your first project

Change to your web server document root, assuming you are using a Debian based server you can find it usually in /var/www (RHEL generally defaults to /var/www/html) :

$ cd /var/www

Create a project using the following command :

$ zf create project <project_name>

Where <project_name> is the name of your project in lowercase alpha numeric form (no symbols, spaces, uppercase letters (hyphens and underscores are OK))

Link your Zend library to your projects library directory as such :

$ ln -s ~/bin/Zend /var/www/project_name/library

Where /var/www is your web server document root and project_name is the name of your project.

If all went well – point your browser to your web server hostname or IP / your project name / public ( http://example.com/project_name/public ).

That is all for now – we’ll get into the actually writing some code next time. Leave me some comments below!

At least once a week I am approached with a rewrite or modification to someone else’s code.  I decided to take on the most recent mod for a friend and am not enjoying it one bit.  It is getting harder and harder for me to take on new projects because of garbage like this :

Bad Code

What the hell kind of form validation is that?!

My question is how does this pass company standards?  How are people getting away writing this rubbish and being paid top dollar over someone who codes to standards and follows MVC.

I am definitely no PHP guru – but for god sakes start writing maintainable code people!

If you are wondering what inspired this rant – take a gander at this gimmicky product… I need a drink.

Displaying HTML rows with offset background colours is a great way to present large amounts of data in a table – plus it looks nice.

Zebra Table Sample

Here are a few ways I display data in this format :

1. PHP Method (for use with browsers with no JavaScript or CSSv3)

PHP Zebra Table

How it works :

We set a variable (i) to the value of 1. We then add 1 to i until it reaches 10.  Within the loop we determine if there is a remainder when dividing i by 2, this lets us know if the number is even or odd.  We add an odd class to every odd table row – and and even class to every even table row.

Why choose this method :

Choose this method when you know your users will be using older browsers or are unsure if they have javascript enabled.

2. CSSv3 Method (For use with newer browsers)

CSSv3 Zebra Table

How it works :

CSS sets the ‘nth-child’ to use the defined background colour.

Why choose this method :

Simplicity!, however beware of outdated browsers.

3. jQuery (for use with JavaScript enabled browsers)

jQuery Zebra Table

How it works :

Similarly to the CSSv3 method above – however does not require CSSv3 support in the browser.  It adds the class ‘odd’ to every other row in the table.

Why choose this method :

Simple to implement however requires JavaScript – do not forget to load jQuery in your document head!

This is a great technique for use with large forms with many values you need to save.  It can get in the way if you need individual validation for each value – however it can save a whole ton of time when submitting any number of form fields.

The video isn’t super high quality so I have attached the source here.

This morning I added Growl notifications to Asteristickies using a wonderful PHP class found here.

You do not need to add any third party software to make this work, presuming you have Growl already installed.  Configuration is minimal and notifications can be sent to any routable hostname . address.