Thursday, April 14, 2011

Directory structure in Zend Framework

Using ZF you can create your project as you wish but as its of MVC Architecture we need to follow simple rules like separating model, view & controller. So in order to achieve this you can use any of the two major classification in ZF,


Conventional Directory Structure: You have single MVC to cover your entire project.
index.php
.htaccess
library/
application/
         Bootstrap.php
configs/      application.ini layouts/   scripts/       layout.phtml controllers/          IndexController.php          TestController.php models/ forms/ views/ scripts/      index/         index.phtml      test/         test.phtml helpers/ filters/
If your project is big enough to have more modules the basic structure won't fit you so i recommend you guys to follow,

Modular Directory Structure: Its the reliable and very useful directory structure as far as i know, You can use this way to manage projects of any size. And more importantly in this style your entire project can be split up into several modules and it'll be very easy to manage & update individually.
index.php
.htaccess
library/
application/
         Bootstrap.php
configs/
     application.ini
layouts/ 
     scripts/
          layout.phtml
modules/
     default/
          controllers/
                   IndexController.php
                   TestController.php
          models/
          forms/
          views/
             scripts/
                  index/
                     index.phtml
                  test/
                    test.phtml
             helpers/
             filters/
     blog/
       controllers/
                IndexController.php
       models/
       forms/ 
       views/
          scripts/
               index/
                  index.phtml
          helpers/
          filters/
Please remind that either you need to specify "Default" module in configs file else you can create a module "default". With this you can decide about your directory structure in ZF.

In Htaccess file you need to give the following to rewrite all request to index.php by this single entry pont we achieve bootstrapping in ZF.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

No comments:

Post a Comment