Monday, June 18, 2007

Tutorial MVC pattern for Zend Framework

I like to use the Zend Framework (currently v1.0.0 RC 2) and I like to use a Model-View-Controller (MVC) pattern to divide my business logic, my visual stuff and my own scripts. What I didn't find on the net was an actual example that would show you how to set up a basic application using the ZF and MVC, with the ZF standards in mind.
So, for my own reference (and the rest of the world) I write here a simple application using Zend Framework and the Zend Framework MVC model.

This tutorial uses LAMP settings, so for other setups you need to figure some stuff out yourself (and add them here as comments ;-)

My setup:
  • Linux: 2.6.18
  • Apache: 2.2.3
  • MySQL: 5.1
  • Php: 5.2.1
  • Zend Framework: 1.0.0 RC 2
Step 1: Getting the Framework
Go to www.zendframework.com and download the latest version of Zend Framework. For easy maintenance, unpack the files in the /opt directory using version info in the directory (e.g. /opt/zend_framework_1.0.0_rc2).
Symlink /opt/zf to /opt/zend_framework_1.0.0_rc2, so you can switch easily to newer versions.
dev@system: # ln -s /opt/zend_framework_1.0.0_rc2 /opt/zf

Step 2: Setting your Apache server
We use a virtual host for our development
<virtualhost *:80>
  ServerName demo.example.com
  ServerAlias demo
  DocumentRoot /srv/www/htdev/demo
  <Directory /srv/www/htdev>
    Options Indexes FollowSymlinks
    AllowOverride All
    Order deny,allow
    Allow from 127.0.0.1, localhost
    DirectoryIndex index.php index.html
  </Directory>
</VirtualHost>

Step 3: setting up a development environment
ZF recommends the following default layout:
/applications
  /config
  /models
  /views
    /scripts
      /index
        /index.phtml
      /error
        /error.phtml
    /filters
    /helpers
  /controllers
    /IndexController.php
    /ErrorController.php
/htdocs
  /index.php
  /.htaccess


Step 4: Create the bootstrap
Adjusting /htdocs/.htaccess with the following lines:
RewriteEngine on
RewriteRule !\.(js|ico|gif|jpg|png|css)$ index.php


Your bootstrapfile is /htdocs/index.php. This is where all requests pass thanks to the adjustments in the .htaccess file.

//include path to zend framework and models
set_include_path('.' . PATH_SEPARATOR . '/opt/zf' . PATH_SEPARATOR . '../application/models/');

//timezone and time options

date_default_timezone_set('Europe/Brussels');

//include the Front controller to handle all business logic
require_once 'Zend/Controller/Front.php';

//set the controller directory
Zend_Controller_Front::run('../application/controllers');


This is the basic you'll need to start running your ZF MVC.
In the next post I write a little application using this setting.

Saturday, June 16, 2007

Dutch PHP Conference 2007

Dutch PHP Conference 2007

My collegues and I visited the Dutch PHP Conference in Amsterdam, where we discovered a lot of PHP enthousiasts and participated on several interesting sessions.

The two first sessions were actually great.
The first given by Cal Evans (DevZone, Zend Technologies) about mash-ups was light and funny.
The second given by Kevlin Henney about Objects of Desire was a non-technical approach to the Object Oriented way developers tend to think. Absolutely great.

A TUX that really runs Linux


A TUX that really runs Linux

Today I went to the Dutch PHP Conference in Amsterdam where I met a guy running around with Tux, the cute little pinguin that has become the symbol for Linux. When I spoke with him, he told me it wasn't just a cute thing you could put on your desktop, but that it was in fact a complete webserver, ready to run Apache and PHP 5.

So he gave me the link to the site where you can buy this cute little gadget that is actually a cool device. See for yourself at http://www.acmesystems.it.

Tuesday, June 12, 2007

UML Class Diagrams

One of the things you need to master if you're a developer is to read, understand and create UML Class Diagrams, especially if you develop in a Object Oriented way, since the Class Diagrams are your building blocks.

For me, a Certified Zend PHP Engineer, it's a brave new world challenging the different elements to create UML schemes. Although it's pretty straight forward, things like relationships, containment, inheritance and associations I still need to master to create decent UML Class Diagrams.

Luckily on my Linux workstation, I have a tool available to create nice UML schemes, called Dia. The advantage is that I can export each scheme into several othere formats like SVG, JPEG, PNG, XML and more.
Creative Commons License
This work is licensed under a Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 License.