Developing software in the Real World

Default Dirs

There’s an interesting thread on the ZF mailing list called Default Dirs which deals with where to put your code. It’s well worth a read.

I’ve touched on this before, but thought I’d update my half a dozen readers on my current thinking :)

The manual suggests:

My current directory stucture currently looks like:

As you can see I’m basically still following the manual, but have tweaked. I have used www rather than document_root because I have a scripts directory and want to emphasise that the stuff in www is for the web server and not for cli. I’m reasonably sure that anyone who has ZF experience could work out what’s going on anyway.

Also, you might have noticed that I store config.ini in /app; It seemed like the logical place as there’s only ever going to be one of them. I’ve also got a tests directory and a schemas directory. Schemas is for some work in progress stuff based on the ideas in Ruby on Rails’s Migrations system. I’ll write about it when I get a chance to actually make it all work!

An interesting question came up about the admin pages of an application. There are two alternatives:

  1. “within the site”
  2. “separate look and feel”

To be clear, in either case, you would use authentication to determine what the user has access to, but the way you present it is different.

In the first case, the “news/add” action would display a form within the look and feel of the website. i.e. the user doesn’t change context, but just gets some extra menu options and features. In the second case, the user logs into a section of the site that looks completely different and has it’s own menu system and features. Think about the admin you get for WordPress when writing a post and compare to the main site as an example.

I will probably do both types depending on the site. For community sites, I like to use the admin within the site feel as it makes it much easier for community members to take on roles like forum moderation. For corporate sites, I prefer a separate admin because the designs that customers like are useless for administration!

To implement, I am going to look at using a separate directory for the admin controllers and views as I think it will make it quicker to find the file that I’m looking for when I’m mainting it 2 years later.

Thus, I think something like this will work:

I’ll let you know if it works :)

2 thoughts on “Default Dirs

  1. Thanks for that; we're just starting a new project at the moment (based on Propel+Smarty etc), and I think I might your structure can fit that quite well (and it saves me from trying to think of something suitable).

    Historically, I've tended to only have a few directories; e.g something like :

    —-/sql – db schemas etc
    —-/docs – req. specs etc.
    —-/tests – any automated tests etc.
    —-/php – controllers and static html
    ——/templates – smarty files


  2. For the most important thing is to get most of the code out of the document root. I know that in theory htaccess prevents access to the bits you don't want people to see, but in the real world mistakes happen.

    I didn't mention docs cos we keep those separate from the code along with the PSD files and other large "original works" that aren't needed for the website itself.

Thoughts? Leave a reply

Your email address will not be published. Required fields are marked *