Welcome Guest, Not a member yet? Register   Sign In
Modular Routing (extension to Modular Separation)
#1

[eluser]gerben[/eluser]
This code builds upon Zacharias' wonderful Modular Separation. I've tested it with version 2.4.1

In my application I found it helpful to make the routing-rules for modules modular as well. This way, a module can be really plug-and-play, because you can add your module-specific routes within the module folder. I thought someone else might find it handy, that's why I post it Smile

First, create a routes.php file in your module's config folder. This file will contain all your module-specific routes.

modules/module_name/config/routes.php

Then, in your default routes.php (application/config/routes.php) add the following lines:

Code:
// check for installed modules automatically
// if a module has a routes.php, include it

$exclude = array('.', '..', 'index.html');

$handle = opendir(APPPATH.'modules/');

while ( false !== ($file = readdir($handle)))
{
    if(!in_array($file, $exclude))
    {
    $installed_modules[] = $file;
    }
}

closedir($handle);

foreach($installed_modules as $module){

    if(file_exists(APPPATH.'modules/'.$module.'/config/routes.php')){
        include(APPPATH.'modules/'.$module.'/config/routes.php');
    }

}

That's it! Have fun!
#2

[eluser]vbnullchar[/eluser]
noob question... whats the use?
#3

[eluser]hostingx[/eluser]
well, that was the same question that came to my head when i read this Tongue haha

Whats the use to have a router per module?
#4

[eluser]esra[/eluser]
[quote author="hostingx" date="1193776906"]well, that was the same question that came to my head when i read this Tongue haha

Whats the use to have a router per module?[/quote]

Better encapsulation. Modular separation modules currently include subdirectories for their own libraries, plugins, helpers, models, controllers, views, and configuration. This change to the Modular Separation MY_Router.php extension allows modules to include their own route specific information within a module's directory structure. With the upcoming module installer currently under development, this change minimizes the files that need to be changed outside of a module's directory structure.
#5

[eluser]vbnullchar[/eluser]
can this be a solution for multiple applications to communicate?
#6

[eluser]gerben[/eluser]
[quote author="esra" date="1193791526"]this change minimizes the files that need to be changed outside of a module's directory structure.[/quote]

Yeah, that's exactly what it's for: making modules as standalone as possible. So they can even be easily be shared between different applications.

Quote:can this be a solution for multiple applications to communicate?

Well, modules can easily be seen as applications-within-an-application, so in that sense... My addition just helps to make modules even more independant of the main app, so you can just drop it into your modules folder, and it'll work without editing much/any of your app's source code.




Theme © iAndrew 2016 - Forum software by © MyBB