|
|||
|
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 :
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
PHP Code:
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 :
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 |
|
|||
|
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 |
|
|||
|
Thanks for your suggestions.
Quote:
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 |
![]() |
| Thread Tools | |
| Display Modes | |
|
|