Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Zend modules in modules

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.

like image 773
Rick de Graaf Avatar asked Nov 04 '10 13:11

Rick de Graaf


1 Answers

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).

like image 58
Fge Avatar answered Sep 29 '22 00:09

Fge