6

I'm wondering of it's possible to create a module structure in a module (or something that appears like that)

Currently I use an admin module, using urls like this:

public/admin/index/index

with a folder structure like this:

applications
-- modules
---- admin
------ controllers
------ views [and so on]

I would like to use these kind of urls:

public/admin/news/index/index
public/admin/gallery/index/index

Where news and gallery are modules

The folder structure would look like this

applications
-- modules
---- admin
------ controllers
------ views
-------- scripts
---------- modules
------------ news
-------------- controllers
-------------- views [and so on]
------------ gallery
-------------- controllers
-------------- views [and so on]

Is this possible? I tried adding another module in my bootstrap:

$moduleLoader = new Zend_Application_Module_Autoloader(array(
            'namespace' => 'Module',
            'basePath' => APPLICATION_PATH . '/modules/admin/views/scripts/modules'));

But that didn't work out. I could create news, gallery and such modules and load them in my admin layout. Everything would be in in the same style and menu as the rest of the admin but I would rather see it my way (if it's possible)

If I want something completely out of the question or have any tips, ideas, please let me know.

Charles
  • 50,943
  • 13
  • 104
  • 142
Rick de Graaf
  • 968
  • 1
  • 14
  • 35
  • 1
    You should do it the other way round. Place an AdminController in each module. This keeps all module logic in one place and not in many. You probably could add submodules but you'd probably have to rewrite a lot of the existing framework for this as this isn't implemented by intention. – Fge Nov 04 '10 at 15:27
  • Could you explain it a little more? I think I don't quite understand how this would translate, but I like the sound of it... – Rick de Graaf Nov 05 '10 at 08:41

2 Answers2

11

A Module is a collection of logical linked functionality (for example, a gallery). To keep things simple, you should store all related code for a module in it's directory (this also includes any admin-tasks). In your adminModule you have the code of several other modules, which makes both modules hard to reuse as they all depend on the AdminModule and the AdminModule depends on all other modules. This totally breaks the idea of modules. If it helps to understand, you can see the controllers as submodules (it's wrong I know, but maybe it makes understanding easier).

So at first you could do something like this:

  • Gallery Module
    • ImageController (viewAction, browseAction,...)
    • AdminController (editImage, uploadImage, ...)
    • ...
  • User Module
    • SettingsController
    • AdminController
    • ...

But again you split the code for one entity over different Controllers. Like in the ImageController you handle the viewing of images but the editing and uploading is done in the AdminController.
So (it least that's how I do it):

  • Gallery Module
    • ImageController (viewAction, addAction, editAction, deleteAction, ...)
    • GalleryContoller (viewAction, addAction, editAction, deleteAction, ...)
    • ....

This keeps all stuff together that logicaly belongs together. One controller is responsible for all actions for one entity (like the ImageController for all actions concerning one image, the GalleryController for actions concerning gallerys). This also includes administrative tasks.
If you do it this way, there probably is no real AdminModule. It'd only be some kind of navigation linking to the administrative actions of each Module/Controller.

You sure can rewrite the zf to support submodules. This would involve:

  • Adding a route that supports submodules (easy one)
  • Rewrite the Dispatcher to support submodules
  • Rewrite the Autoloader for submodules
  • Adding several other directories to Plugin-Loaders & others

But this isn't done with any mvc framework I've ever seen as this usually implies a design-weakness (again, in my oppinion) and a general performance loose (the more directories to look up for the autoloader the worse).

Fge
  • 2,971
  • 4
  • 23
  • 37
  • Thanks for explaining! I think I understand and will be looking into this the next few days. Thanks! – Rick de Graaf Nov 05 '10 at 15:06
  • Another kudo. Good explanation and well thought out reasoning. Point me in the right direction. Thanks. – Fatmuemoo Dec 06 '10 at 19:23
  • hmm. How would you output several modules on the same page? meaning something like widgets? Is that possible? I know I can use action view helper - but that's AFAIK will trigger entire dispatch loop - right? – Stann Mar 01 '11 at 13:56
  • 1
    @andre : yes, it would. actionstack is probably the easiest way to do this. Especially for widgets there is no "only way" to do it. It absolutly depends on your aim and should be it's own question with more details ;) (is the location static, how many, how flexible,....) feel free to notify me with this question :) – Fge Mar 01 '11 at 15:47
  • http://stackoverflow.com/questions/5171160/zend-reusable-widgets-plugins-miniapplications – Stann Mar 02 '11 at 17:32
0

The ZF directory structure is customizable, mainly by:

  • front controller options (e.g. setControllerDirectory(), addPluginPath() etc.)
  • view options (addPath(), addHelperPath()
  • autoloaders, e.g. _resourceLoader in module bootstraps
takeshin
  • 49,108
  • 32
  • 120
  • 164