Welcome Guest, Not a member yet? Register   Sign In
Dynamic application defining in 5 lines of code

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:
$application_folder = 'application';
Where application is the name of your application's folder.

Final step 3: And replace this code to this:
$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? :-)

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

Just for fun. Maybe someone needs this.

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

You can build modular cms with it. With it you will not have any troubles with hmvc.

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.

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

jelmer, agree with you.

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

Ok, I understood my error.

Theme © iAndrew 2016 - Forum software by © MyBB