Organizing the Application Controllers |
[eluser]Xeoncross[/eluser]
Organizing the applications directory into the default: APPDIR ->controllers -->module1 -->module2 -->module3 ->models -->module1 -->module2 -->module3 ->views -->module1 -->module2 -->module3 is more messy in large projects than: APPDIR ->modules -->module1 ---->controllers ---->models ---->views -->module2 ---->controllers ---->models ---->views -->module3 ---->controllers ---->models ---->views How can I expect to build a simple drop-in-place "posts" module or "twitter feed" module if the code and views are spread around in different folders? I want to propose a re-write of the codeigniter.php file to something more like this that will allow users to build there site either way. Code: <?php Does anyone else think this is a better way to organize the system? ;-)
[eluser]Michael Wales[/eluser]
Some people prefer this method of organization (personally, I'm with the former - default CodeIgniter structure). Check out Matchbox for the organizational change you discussed and Modular Extensions for a full-fledged HMVC solution.
[eluser]Randy Casburn[/eluser]
@Xeoncross -- what if you have 8 modules that share common models and/or controllers? do you now have to copy them to each and every directory for the 8 modules? I reuse as much code as I possibly can and the current layout allows me to do that. It seems you're concept would require that I dump copies of copies of copies of files where ever they are needed. One simple example would be an authentication/access control mechanism that is shared by all modules. Thoughts? Randy
[eluser]wiredesignz[/eluser]
@Xeoncross, While your method is fine for loading controllers, it doesn't allow other module files to be located and loaded. You may or may not be aware that both Modular Extensions and Matchbox allow for modular organizational structure.
[eluser]Colin Williams[/eluser]
I also prefer the basic MVC structure for some of the reasons Michael and Randy mentioned. But matchbox and modular extensions seem to be actively maintained, so if you must...
[eluser]Xeoncross[/eluser]
[quote author="Randy Casburn" date="1216546808"]@Xeoncross -- what if you have 8 modules that share common models and/or controllers? do you now have to copy them to each and every directory for the 8 modules?[/quote] No. If you look at the code above you will see that you can place the modules that you want in a "modules" folder OR core controllers can remain in the default CI setup. For example, with the above Code I have my system setup like this: Code: APPDIR @wiredesignz: Would you mind giving an example? @michael Wales: Thanks! Matchbox looks like a good start. I did not intend to replace the default CI setup - But with just a few changes to the CI system we could have a more flexible layout system that would allow people to organize their site in any way they wanted with the default being the way it is now. Most people dont share the controller/module/view combos they create - in which case the default method is awesome - but for people like me that want to create something I can just hand to someone - a "modules" method would be better... Flexibility. ;-)
[eluser]wiredesignz[/eluser]
@Xeoncross, Download Modular Extensions - HMVC from the link in my signature below, ME functions exactly the same as Matchbox but has many additional features also.
[eluser]Colin Williams[/eluser]
Well, when you start distributing "modules" you might run into naming clashes. Let's say my site already has a models/category_model.php, then you distribute an MVC module with it's own module/model/category_model.php file. Sure, you could cascade to the "nearest" model that is requested and the modules won't clash (I think wiredesignz Modular Extensions does this), but you've still got a problem: You've got 2 models for 1 kind of data. Maybe this situation is a bit pie-in-the-sky, because why would you implement a module if you already have a working system, but I'm not so sure it would be that uncommon. With that said, I think Modular Extensions is probably going to be suited well for you.
[eluser]wiredesignz[/eluser]
@Colin, Any PHP application will fail if you try to load identically named classes. If you build a `distributed` module it would be wise to use psuedo-namespaces, similar to Neophyte and his Khaos libraries. You really are clutching at straws to find fault in modules my friend.
[eluser]Colin Williams[/eluser]
No, not finding faults in your module, wiredesignz, just faults that could occur implementing it. And of course PHP with throw an error in that case. Bad example I raised using the same name. I'm still interested to know what happens in this sort of instance though, where you're modeling the same data in different ways. I guess you just choose the best model and move forward with it, updating old code to match the new API? Regardless, though, you aren't going to run into this situation if you stick to vanilla MVC. |
Welcome Guest, Not a member yet? Register Sign In |