07975 997026 enquiries@ harpanet.com
The ZF default structure bundles everything together in one place, ensuring as little code duplication as possible and making it relatively easy to find what you want, but as your project grows the number of files in each folder becomes unweildly in my view. There are other ways of Choosing Your Zend Framework Application Layout but I prefer the more segmented, logical and neater approach of Modules.
|A - Default Folder Structure||B - Modular Folder Structure|
Column A shows the default application structure created by the zf create project command line tool. This structure bundles all controllers, models, views, scripts, and layouts together into their respective folders within the application folder. This is fine I think for relatively small projects, but as you're using Zend Framework the likelihood is that the project is intending to become much larger and more complex.
Here I think we have to digress a little to think about what is meant by a Modular Structure and why we would want a Zend Framework Modular Structure. Looking at Column A, we have already created a 'module' in effect by putting our project (Square) into the 'square' folder. Okay, so we're calling this a project, but in a corporate environment it is quite likely that our web space will contain a number of 'projects'. So, are these now 'projects' or 'modules' of our website as a whole? And how far back do we keep going; should our public web root be the top level?
What about Extranet functionality, where would that sit? (Personally, I reckon we are now looking at different Applications rather than Modules within an Application, and Rick Stevens discusses this very clearly in his Zend Framework Multiple Applications blog post so I won't repeat it here.)
Admittedly, for most small-business or personal websites, we probably don't need to think about this level of complexity, but then we probably won't want to be using ZF for the website either (maybe CodeIgniter is a better choice in these instances). However, using ZF (through choice or necessity) means we have to decide where the 'module' part of Modular applies to us. For the Square project, I've decided that Modular means that I want to separate out my Default features from my News features from my Admin features from my Reviews, etc. If I wanted another Company News feature, related to the overall company and not specifically about Square News, I would have to create another Project for Company, requiring a different sub/domain name if we plan on sticking with the Zend convention of making the 'Public' folder the root of our website.
One consideration in deciding where 'Modular' applies to your project, is to think about how much (or little) code duplication you are happy to put up with. The more modular a project, the more likelihood that you will have to duplicate pieces of code and locate them within each module. eg. the News feature and the Reviews feature may have identical Listing Controllers, but they will have to be maintained separately as there is one copy in the News module and one copy in the Reviews module.
From my basic understanding so far, the difference between Column A and Column B could just be an evolutionary thing, where column A is how ZF has worked to date, but column B is the future direction. I don't know yet, but I can see no drawback in Zend Framework making column B's Modular Structure the default structure created by the zf command line tool. Even if we didn't want multiple Modules, we could then just use 'default' to contain all our files.
Even though ZF implies that it is not designed around any fixed folder structure, it doesn't yield too easily into the Modular structure. For me, a Modular Structure implies that everything relevant to a module is contained within that module. IE. no external references to anything except the Zend library files. It may also reference Company Specific library files if they are relevant to all projects, but not if they only relate to the individual module. To get ZF to comply with this vision of modular structure takes a few changes which are covered individually below.
The steps necessary to get it all working are: