CodeIgniter Forums
Dynamic application defining in 5 lines of code - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22)
+--- Thread: Dynamic application defining in 5 lines of code (/showthread.php?tid=27878)



Dynamic application defining in 5 lines of code - El Forum - 02-23-2010

[eluser]Sbioko[/eluser]
Curious? :-) In this topic I'll explain how you can implement True HMVC using just 5 lines of code. You don't need to use any MY_ classes and additional libraries! So, let's start!

Step 1: Create modules folder and move your application folder into it.

Step 2: Open index.php and find this line:
Code:
$application_folder = 'application';
Where application is the name of your application's folder.

Final step 3: And replace this code to this:
Code:
$application_folder = '../modules/application'; // you must replace application to your default module/controller.

$URL = explode('/', $_SERVER['REQUEST_URI']);
if(isset($URL[1]) && $URL[1] !== '' && is_dir('modules/'.$URL[1])) {
    $application_folder = '../modules/'.$URL[1];
}

That's all! Now you have full HMVC :-) But, there are some known issues with it:
1) You can have only 1 controller per "module" and it must be named same as the module's name. For example: Module Blog can have only 1 Blog.php controller.
2) Security. I think, that here is possible to do PHP-inj. This is just my opinion. You can disagree with me.

So, what are you think about it? :-)


Dynamic application defining in 5 lines of code - El Forum - 02-23-2010

[eluser]Johan André[/eluser]
Very useful... not.
What's the purpose of this?


Dynamic application defining in 5 lines of code - El Forum - 02-23-2010

[eluser]Sbioko[/eluser]
Just for fun. Maybe someone needs this.


Dynamic application defining in 5 lines of code - El Forum - 02-23-2010

[eluser]Phil Sturgeon[/eluser]
I might be missing something, but from here this looks entirely useless.

Perhaps you could explain what it is meant to do, as it looks like it just modifies the application folder a little bit. That allows no cross-module resource loading or any of the real benefits to using modules.

It will also screw with config and, well, most of CodeIgniter.


Dynamic application defining in 5 lines of code - El Forum - 02-23-2010

[eluser]Sbioko[/eluser]
You can build modular cms with it. With it you will not have any troubles with hmvc.


Dynamic application defining in 5 lines of code - El Forum - 02-23-2010

[eluser]Jelmer[/eluser]
You might be able to do that but it's multiple applications and not multiple modules in one application. You're only using the URI to decide what application to use.

And to echo Phil: your config files, libraries and other resources have to be in every application folder and can't be shared.

All you've done is to show how you can load multiple applications from 1 index.php using the URI requested, that's not HMVC.


Dynamic application defining in 5 lines of code - El Forum - 02-23-2010

[eluser]Phil Sturgeon[/eluser]
That kinda what I was getting at Jelmer. There would be no shared code and all application-wide libraries would need to be copied.

This dirty hack and my dirty "Shared resources" MY_Loader.php and this might begin to be vaguely useful, but its useless just those 5 lines.


Dynamic application defining in 5 lines of code - El Forum - 02-23-2010

[eluser]Sbioko[/eluser]
jelmer, agree with you.


Dynamic application defining in 5 lines of code - El Forum - 02-23-2010

[eluser]wiredesignz[/eluser]
This is not HMVC in any form that I'm aware of, I suggest you remove HMVC from the title altogether.


Dynamic application defining in 5 lines of code - El Forum - 02-24-2010

[eluser]Sbioko[/eluser]
Ok, I understood my error.