views:

1407

answers:

4

I'm aware of default directory structure for Zend Framework modular applications that is in the manual.

/application
  /controllers
  /modules
    /admin
      /controllers
      /views
  /views
  /configs
/www
  index.php

But I'm wondering why should I do it this way. It really sux to have the default module in /application and other modules in /application/modules/:moduleName. This is more of a discussion question than a help-me question.

What are the pros and cons of having directory structure like this:

/application
  /modules
    /admin
      /controllers
      /views
    /default
      /controllers
      /views
  /configs
/www
  index.php

From my point of view the only disadvantage is that it's not written like this in default / in manual. I can't see any other. Am I missing something?

Even more - I think that this structure should be default structure for any new ZF application. And I wonder why Zend developers doesn't use it.

A: 

I suppose this way is because :

  • there is a default structure, that is used when there is no module in an application (ie, only a default module -- which means no need for a "default" directory)
  • and, then, you can add modules ; without having to modify the existing structure.

It's an explanation as good as any other, I suppose.


Still, if developping an application that will contain several modules, and knowing this from the start, I'd probably go with the kind of struture you are proposing, and not the default one ^^

Things would be more clear that way, in my opinion -- and I don't see any problem with that !

(In fact, I've that way once, quite some time ago, and have not met any trouble -- but this was not a "complete" application ; more a prototype... )

Pascal MARTIN
I came to state, when mostly my EVERY application has at least two modules (admin / default) and I guess that most developers faces the same situation. I guess it would clear much questions, when the whole application will be "module-ready" out of the box.
Tomáš Fejfar
A: 

I'm strugling with the same problem. But i'm not succeeding in setting this up properly... Why I want to use this is because the modular structure, combined with Zen_Application, instantiates a Module_Bootstrapper which registeres the namespaces in /application/module/name/forms (and controllers, views, models, etc...) automaticly.

The only problem i'm having is getting rid of the 'default' module :S

you can find the topic on Zend Forums here: http://forums.zend.com/viewtopic.php?f=69&t=2394&start=0

Hopefully it'll get answered, ot i'll post it up here.

Nicky De Maeyer
+1  A: 

Actually that is one of the options detailed on http://framework.zend.com/manual/en/zend.controller.modular.html

Your way sounds fine and the point of ZF is you can choose how to manage things yourself. One advantage is slightly less code. In Zend's default approach you'd need to use this:

$front = Zend_Controller_Front::getInstance();
$front->addControllerDirectory('/path/to/application/controllers', 'default');
$front->addModuleDirectory('/path/to/application/modules');

Whereas in the approach you describe:

$front = Zend_Controller_Front::getInstance();
$front->addModuleDirectory('/path/to/application/modules');

Is all you need.

One advantage of Zend's approach is if you don't need modules, then there's no need to run the addModuleDirectory() method. With your approach this would always need to be run, potentially creating a small overhead.

This page http://framework.zend.com/manual/en/project-structure.project.html states having the default controllers directory "inside the application directory provides the best layout for starting a simple project as well as starting a modular project that has global controllers/models/views."

I guess Zend's point of view is that this works for both simple sites with only a default module and more complex ones with multiple modules. It's not hard to work out further modules are in the modules/ directory. But at the end of the day, it's personal preference.

simonrjones
Thank you very much for your complex answer. I missed somehow the section in manual. Too bad, that Zend_Tool doesn't offer this functionality and you'd had to extend it's classes :)
Tomáš Fejfar
well i guess Zend_Tool just offers a default way of doing things. Most developers will probably find your own way. As far as I'm aware it is possible to extend Zend_Tool to do things your way, but I've no idea how complex that is!
simonrjones
+2  A: 

Actually your proposed directory structure is more than appropriate for large and complex applications.

Magento which is world's best Open Source e-commerce solution today has been coded in Zend framework and uses similar directory layout as you propose, this way its very easy to extend and add new modules and manage old ones.

Again for simple apps and for learning Zend I would suggest everyone to stick to the default directory structure.

Sumit Ghosh