Spiga

Zend Framework modular directory structure

by Gabi Solomon

After a lot of thinking and going back and forth about this idea, i finally decided to start using ( learning at first ) zend framework.

The main decision was to go with an already built framework or an inhouse one. And although i really like reinventing the wheel sometimes, i said i will not do the same this time.

After deciding i wanted to use an exiting framework, i had 2 candidates in mind : CodeIgniter or zend framework. The plus for codeigniter was the fact that it went with a more familiar approach to MVC, and the plus for zend was the company behind it. The downside about zend, was for me at least, the size of it, and the fact that it seemed a lot to learn.

But i decided to take a chance and learn Zend. The main problem i had was how to start ( as all things are :D ). Because the have such a freedom in development, i was a little puzzled on how to structure my application.

The only thing i knew was that i wanted to go with a modular structure. From there i did a lot of googling, read and watched a few presentation about this topic and finaly came up with a structure wich is bassed much on Wil Sinclair proposal.

My Zend modular structure

I will try to explain it, why i chose it this way and what each folder contains.

1. Application

The main aplication folder
1.1 Config – Contains application configuration files ( ex: mysql details )
1.2 Controllers – General Controllers, that are common in all modules
1.3 Languages – Holds the language files
1.4 Layouts – This directory is for MCV based layouts.
1.5 Models – This directory holds the application models ( in put them here instead of the modules directory since i belive there are common to all application and its more better this way )
1.6 Modules – I really liked the idea of modules that zend used because it enables you to organize your controllers and views much better in a separate folder for different sections of a website ( for example the main website, editors area and admin panel )
1.7 Views – I also included a views folder in the main application because i though i could use it to store common views for the 3 modules.

2. Data

This folder holds various information that is temporary, like cache, session data etc.

3. Docs

This directory is for documentation automatically generated or hand written.

4. Library

This directory holds the library Zend Framework files and also other folders for your own library (extended from Zend or not). I have one called GSD that extends some zend classes.

5. Public

This directory would contain the public files for your application: index.php. index.php ( this will include the bootstrap.php file from your application/ directory) and the front end assets (css, javascript, images, flash etc )

6. Tests

This directory would hold the application tests. This is a cool feature about Zend that it has support for writing application tests to better test your code during development.

Final Words

Ok this is about it so far. I am still a beginer with zend, and this structure is what i have thought off so far, and it doesn’t have some real application testing. Use it at your own expense :) )
I am sure as i start developing using zend that it will be modified.

Another bad thing about zend is that there aren’t so much resources and real examples about it, this is why i will write about my journey with zend here. Hopefully somebody will benefit from it. :)

Cheers

Related Posts

  • Needless to say, I'm a big fan of the modules in Zend Framework. ... simpler to use the directory structure
  • @olga
    In the application/controllers folder i usually like to place general controllers that are not used anywhere directly but are extended in the modules.
    I am not saying this is the best way ... but this is how i like to do it.
  • Good structure! But...maybe will be better use /application/modules/default/controllers instead /application/controllers etc..? /application/modules/default/ as a matter of fact contains the General Controllers
  • @djaarf
    I am sure its only the main ideea that looks alike ... not the exact article :)
  • After few months of searching material like yours, i start to do it myself (on Russian). And now it looks like the translates of your articles, but i didn't know about your site :) we are just using the same library (ZF). Who can tell that to my visitors =)
  • @ The Willer
    Thanks, i am trying to write as many articles as i can about ZF, and tell about my experience and lessons learned in using ZF
  • It's very handy what you write about. Shame I've found it after about half year of struggling with ZF. Please write some more articles about ZF like U do, not the funny little stuff 'hello world - my first app' like most of posters do. Thanks a lot!
  • Very informative article, which I found quite useful. Cheers ,Jay
blog comments powered by Disqus