If you know anything about me and my profession, you know that I am a extreme advocate of the Zend Framework and its standardization of PHP programming, well Zend has just release v1.5 of the framework.
To be honest, I could beat a dead horse by reiterating what is new in 1.5, however I am going to focus on what I have been working with and so far love about the new version.
Also, You can download my compiled skeleton 1.5 project, complete with the 1.5 Library at the end of this article.
First up is Zend_Form. I don’t care who you are, forms in web development are a pain in the ass. They start off being fun to create, but as you extend, or make changes, or implement validation and other things, they really make you want to pull your hair out. I really like to have HTML coded statically, rather than rendered programatically, but Zend_Form does more than just create HTML elements for you. Zend_Form also takes care of validation, so using OOP format, you can create complex forms with validation without the headache.Once again, instead of reinventing the wheel, have a look at this article on the devzone dedicated to Zend_Form.
Lifting the skirt on Zend Framework 1.5 — Zend_Form
Next Up, Zend_Layout. If you read my last articles, I talked about Zend_Layout. Basically what it does is enable 2 step views very easily out of the box. In my last article, I showed you how to use a front controller plugin ‘SiteTemplate’ to achieve this, which works well, but now Zend has listened and made a fantastic addition. Once again, here is a great article on it.
Code Utopia- Introduction to Zend_Layout 1.5
Last but not least, is a hidden gem that I just learned about yesterday. The greatest addition in my eyes is…… Modular Directory Structures, out of the box. Yes, I know it already existed, but now it is really easy. What this means is, inside your application folder, instead of having single controller/model/view directories, you have subfolders for different parts of your application, and inside of those folders you have folders for controllers/models/views used by that part of your application.
I am a HUGE fan of modularity, probably because I am a neat freak. It cleans everything up, and makes maintenance a cinch. Along with the folder structure, it also sets the router to feed from each folder respective to the request.
For example if I go to www.site.com , with a modular setup, the application will execute the IndexController inside application/modules/default/controllers, and if I go to www.site.com/blog , it will look for application/modules/blog/controllers/IndexController.php . What this also means, is that if you implement Zend_Layout along with a modular setup, you can put a layout.phtml inside each modules views directory and change the layout. This makes things that much more tidy.
it is good to point out that in all modules other than ‘default’ , you will need to prefix the classes ONLY with the module name, but just the class, not the file itself. For example application/default/IndexController.php has a class name of IndexController, while application/blog/IndexController.php has a class name of blog_IndexController, make sense?
Here is a picture of a modular layout, this is also the layout of the skeleton app below.
Zend Framework 1.5 Skeleton Application ——
I have compiled a zip file containing everything you need to get started with ZF1.5.
The application is laid out this way;
- The Public directory is your DocumentRoot.
- The bootstrap file is located behind DocumentRoot in application/config and is included by index.php in the DocRoot.
- htaccess takes care of routing of non-static requests.
- config.ini in application/config has the configuration for DB connection.
- A plain ErrorController is present to catch errors.
- Zend_Layout is implemented using layout.phtml in each modules views/scripts directory.
- It uses… of course, a modular directory structure.
Download the skeleton app HERE



April 21st, 2008 at 9:45 am
ZF ftw. I totally agree with all your points. I had already used Zend_Layout quite extensively and was familiar with the modularity stuff etc., but I was initially somewhat skeptical about Zend_Form…. “it’s not going to be easy to use, it’s not going to let me customize the output easily” and so on. It turned out as another great component, and it easily “bends” to what you want to do with it - be it custom HTML or adding JavaScript tricks to the form.
April 21st, 2008 at 4:49 pm
Awesome, worked right out the box so to speak. Thank you
April 23rd, 2008 at 2:02 pm
Thanks for the comments.
I was really skeptical about Zend_Form as well. I always rather make forms by statically writing the markup.
The great thing about Zend_Form, like you said, isn’t being able to programatically, but how extensive it is. Not only is the great option of validation, but you can create forms statically through a config file, which when you look at it, is a lot easier than writing the markup, it’s cleaner, and very easy to maintain.
I’ve found using ZF to be a godsend to me developing professionally, and haven’t suffered performance issues at all, all in all..
ZF FTW x2 lol
April 27th, 2008 at 5:48 am
I found that the skeleton has a little error. In all the layout.phtml files in all modules you will need to change the first line:
docType(’XHTML1_STRICT’); ?>
To:
Doctype(’XHTML1_STRICT’); ?>
April 28th, 2008 at 1:31 am
Jakob,
Yeah, I actually noticed that a few days ago when I started working on an app on my linux server.
I put together the skeleton at work on a windows pc, and windows file system is case insensitive so I didn’t have a problem with it finding the helpers, but it became clear when I tried it on a linux box.
I was too lazy to fix it or anything, but now that someone has seen it I guess I’ll do it haha.
April 28th, 2008 at 1:59 am
Ok I’ve replaced it with an updated working version of the skeleton app. At least it wasn’t as bad as the first mistake I made.
The first one I almost uploaded had my DB auth credentials in the config file still, good thing I caught it before I uploaded it haha.
May 16th, 2008 at 10:02 am
Hi! Thanks for the skeleton, but I’m having some problems, and hopefully you can help me.
At the moment I’m on Windows using Wamp and with the mod_rewrite module loaded, but the only way I can access the index controller and the blog controller is through:
http://localhost/skeleton/index.php & http://localhost/skeleton/index.php/blog
It throws a bad request if I try the url: http://localhost/skeleton/
I then change the .htaccess file to
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule !\.(js|ico|gif|jpg|png|css)$ index.php
and the http://localhost/skeleton/ url works, but to go to the blog I have to enter http://localhost/skeleton/index.php/blog because http://localhost/skeleton/blog doesn’t work…
It’s not only with your skeleton that this happens, I’ve been trying in so many different ways and it never works as it should.
Thanks for the help.
May 16th, 2008 at 5:37 pm
I have heard there have been some weird happenings with rewrite on Windows. I have not tried setting up a server though. I do have a local ZendCore install on my laptop at work. When I get there tonight I will try to see if I can replicate your problem and find a fix.
May 17th, 2008 at 12:25 am
Ok I attempted to recreate your problem, but could not. Although it may not be an option, I would suggest steering away from the WAMP, XAMP series of installs, and going for a ZendCore install , and a MYSQL installation.
May 18th, 2008 at 7:34 pm
Thanks for the response.
I installed ZendCore and could not make the rewrite work.
I tried on my Fedora 9 install and it works like a charm…
This is really weird…
May 19th, 2008 at 5:08 pm
I’ve just found out that the URL rewriting is in fact working both in windows and Linux when I place my websites on the document root of apache.
If I have an Alias, the rewriting does not work.
How can a simples Alias make this happen ?
May 20th, 2008 at 7:33 am
If you mean virtual hosts, make sure the vhosts config has allow override all inside the directory definition. Here is an excerpt from my httpd-vhosts.conf
# Dev
<VirtualHost *:80>
DocumentRoot /home/blah/dev/public
ServerName dev.joeyadams.net
ServerAlias http://www.dev.joeyadams.net
<Directory "/home/blah/dev/public">
Order allow,deny
Allow from all
AllowOverride all
</Directory>
</VirtualHost>
May 20th, 2008 at 10:24 am
It’s not a virtualhost, it’s just a simple Alias.
Anyway, I found the solution, if you have an Alias like this:
Alias /cartazleiria/ “d:/workspace/cartazleiria/public/”
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
Allow from all
The .htaccess file should be:
RewriteEngine on
RewriteBase /cartazleiria
RewriteRule !\.(js|ico|gif|jpg|png|css)$ index.php
So many time for such a small change… It’s always the same thing!
May 21st, 2008 at 4:46 am
Looking at the structure, I cant see how the Models for each Module is Auto loaded. or does this need to be done manually per controller?
May 23rd, 2008 at 2:26 am
I have not created an app with the skeleton yet, so have not had ability to troubleshoot things like this, so it is good to come across them.
I took a look at it, and modified a existing idea for a front controller plugin, this sets include path to the global models directory located in application/models , also the module models directory located in application/modules/modulename/models .
So now you can put your models that multiple modules need to use in the global directory, and models specific to each module into the modules/models directory, and just use the Zend_Loader::loadClass(’Model.php’); to include with ease.
I have uploaded the fixed app.
Thank you.
May 23rd, 2008 at 10:49 am
Hi again.
I have a small problem and I believe you can solve this with ease.
I’ve created a class with the login form on modules/default/forms/LoginForm.php and I’m trying to include it in the UserController wich is on modules/default/controllers/UserController.php.
What I’m doing is:
require_once ‘../forms/LoginForm.php’;
But this doesn’t work as I expected. I already made it work including the forms dir in the include path but this is not a good solution.
Anyone knows how can I make it work ?
June 25th, 2008 at 11:25 am
Hello!
I’ve noticed an error: the link attached to this post, cannot be downloaded:S
Please, correct the problem, because i want to take a look at your skeleton app for educational reason!
Thank you!
June 26th, 2008 at 5:49 am
Hey butaarcu, Thanks for that, I have been messing around changing the server around getting ready for my move to versioning and the problem was caused by improperly ordered virtual hosts. So you were actually accessing one of my projects that is under development!!! eek.
All fixed now.
June 26th, 2008 at 2:46 pm
Many thanks for you!