Welcome, Guest. Register Now!
   
Mark Forums Read Mark Forums Read Mark Forums Read


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-03-2007, 02:14 PM
Junior Member
 
Join Date: Jul 2007
Posts: 3
Lightbulb MVC overloading

I'm trying to make with ZF one common design that I'm using on other web application that I'm working with/on.

As the thread title states, it's about MVC overloading. The idea is to be able to load controllers and view scripts from different locations according to their existence and priority set initially .

I want to setup two modular structures the first contains the shared modules and a second one the application specific modules.

For example I have 3 modules :
  1. Page - manages general propose pages on the website (intro, about us, contact us, etc.)
  2. Navigation - manages site navigation (menus, locator, etc)
  3. Product - manages products (whatever you want)

The modules "Page" and "Navigation" are shared modules and I want to use them on many applications. The module "Product" is specific for the current application.

The module directory structure is in the form :

Code:
// shared modules folder
shared/
    modules/
        page/
            controllers/
                IndexController.php //default way to load pages
                ContactController.php //default way to manage contact us form
            models/
            views/
                scripts/
                    index/
                        index.phtml // default page layout 
                    contact/
                        index.phtml // default contact us page layout
        navigation/
            ...
// my current app modules folder
app/
    modules/
        product/
            ...
        page/
            controllers/
                ContactController.php // overload the default contact us management
            models/
            views/
                scripts/
                    index/
                        index.phtml // overload the default page layout
Currently with ZF in my bootstrap I can do :

PHP Code:
// set shared modules
$frontController->addModuleDirectory('shared/modules');
// set application specific modules
$frontController->addModuleDirectory('app/modules'); 
Request : page/index/index

The dispatcher will search in 'app/modules' (module directories are added FILO) for folder 'page' if the folder exist it will route to it. But in app/modules/page/controllers/ the index controller doesn't exist, exception is thrown, as expected.

Here I want :
  1. The dispatcher to search the others module directories for the controller
  2. Search again from the first module directory for the view script
In this way I can use the shared Page IndexController but the specific view script for my app overloads the default page layout script.

Request : page/contact/index

The dispatcher will find the controller but the view script doesn't exist. I assume here that the contact controller is using the view renderer in the most classic way.

Here I want : The dispatcher to search in all the module directories for the view script, according to the route.
So I can use my new custom ContactController but with the default contact page layout.

All the searches are made in the way the addModuleDirectory is called FILO (first in last out). In this way we put priority in overloading between the modules.

Any ideas how I can implement this ?

I think it's possible to do it with one controller plugin, but I'm not very good in OO design so any help with ideas and suggestions is welcomed.
I'm able to write scripts with this level of complexity but I lack good design background.

Thanks
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 10-04-2007, 05:49 PM
Member
 
Join Date: Jun 2007
Posts: 33
Default

The only way I think you can do this is to extend your controller with those rules you want inside of it. In this case, I don't know if the effort is worth it.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 10-04-2007, 09:48 PM
Junior Member
 
Join Date: Oct 2007
Posts: 5
Default

Maybe if you write a plugin , and implemente the routeShutdown method you are able to implement your custom logic in it. In the method , first check if the controller exists by generating the controller name with the provided route method ( I don't recall it's name but it exists).
You can check if it exists or not by using Zend_Load and catching the generated exception(if any). If it does not exist , implement your custom logic. Does this help?
Anyhows , you can modify and alter the route in a plugin in any phase of the the dispatch process. I have used the previous aproach to implement error handling in previous releases of ZF.
regards
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 10-06-2007, 06:56 AM
Junior Member
 
Join Date: Jul 2007
Posts: 3
Default

Thanks for your suggestions.

Quote:
The only way I think you can do this is to extend your controller with those rules you want inside of it. In this case, I don't know if the effort is worth it.
I don't see any other way to share functionalities (modules) in many apps. There is other way and it's symlinks on *nix based machines. To make symlink in my app for each shared module. Is is worth ? Yes, definitely. You can make common modules and reuse them !

As Khelo says I think it's possible to do it with a controller plugin using the routeStartup and routeShutdown. I'll give it a try to see if I can do something.

Thanks
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 11:11 PM.