Welcome Guest, Not a member yet? Register   Sign In
Modular Extensions - Version 4.3

[eluser]codex[/eluser]
[quote author="wiredesignz" date="1208086504"]One thing you could try is a routes.php file in the application/modules directory then have an include APPPATH.'modules/routes.php'; directive in config/routes.php[/quote]

I'm not gonna take credit for having this idea. It was because of Elliot Haughin's Blaze that I thought of it. He has this piece of code, implying that it *is* possible (if I read it correctly). And if it proves to be working, would you consider putting this into ME?


Code:
// Add a route for a module to that module

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

if ($handle)
{
    while ( false !== ($module = readdir($handle)) )
    {
        // make sure we don't map silly dirs like .svn, or . or ..
        
        if (substr($module, 0, 1) != ".")
        {
            if ( file_exists(APPPATH.'modules/'.$module.'/'.$module.'_routes.php') )
            {
                include(APPPATH.'modules/'.$module.'/'.$module.'_routes.php');
            }
            
            $route[$module] = $module;
            $route[$module.'/(.*)'] = $module.'/$1';
        }
    }
}

$route['default_controller'] = "page";
$route['scaffolding_trigger'] = "";
$route['(.*)'] = "page/index/$1";

[eluser]wiredesignz[/eluser]
Well it looks great so yeah try it by all means, but it's outside the scope of ME as part of the library but you could add it to the ME wiki page as a add on for sure.

[eluser]codex[/eluser]
All modules are by default placed in the 'modules'-folder, but organisation wise I would like to be able to have different modules in their own folder:

- modules
|-- admin
|-- public

is this possible? And maybe able to set the paths in a config file?

[eluser]wiredesignz[/eluser]
Modules can (and should) be organised into their own directories under application/modules like your diagram.

The default controller for each module would be named the same as its directory.
ie: application/modules/admin/controllers/admin.php
ie: application/modules/public/controllers/public.php <-- note public is a reserved word in PHP!!

Hope this helps.

[eluser]codex[/eluser]
[quote author="wiredesignz" date="1208234422"]Modules can (and should) be organised into their own directories under application/modules like your diagram.

The default controller for each module would be named the same as its directory.
ie: application/modules/admin/controllers/admin.php
ie: application/modules/public/controllers/public.php <-- note public is a reserved word in PHP!!

Hope this helps.[/quote]

Sorry, I wasn't clear in my post. I meant application/modules/public/module_name/controllers/module_name.php and application/modules/admin/module_name/controllers/module_name.php.

See what I mean??

[eluser]wiredesignz[/eluser]
Yep, I see now.

If you prefix the module_controller with its sub-directory/module_name it should stil load ok.

ie: modules::run('public/module_name/module_controller'); or modules::run('admin/module_name/module_controller');

Let me now if you have difficulty.

[eluser]codex[/eluser]
[quote author="wiredesignz" date="1208254213"]Yep, I see now.

If you prefix the module_controller with its sub-directory/module_name it should stil load ok.

ie: modules::run('public/module_name/module_controller'); or modules::run('admin/module_name/module_controller');

Let me now if you have difficulty.[/quote]

Code:
modules::run('cms_module', '', 'listForms') //-> default, works
modules::run('public/cms_module', '', 'listForms') //-> doesn't work
modules::run('public/cms_module/cms_module', '', 'listForms') //->nothing either

Error:
Code:
Unable to locate the requested file: publiccms_module/views/list_forms.php

Looks like the / after public is being stripped.

[eluser]wiredesignz[/eluser]
Good catch codex. Wink I will check and fix this.

[eluser]wiredesignz[/eluser]
Codex could you replace this and try again:
Code:
//line 132 of modules_helper.php
return array($path2, str_replace(EXT, '', $name), str_replace('/','', $path));

//with this
return array($path2, str_replace(EXT, '', $name), substr($path, 0, -1));

[eluser]codex[/eluser]
[quote author="wiredesignz" date="1208269422"]Codex could you replace this and try again:
Code:
//line 132 of modules_helper.php
return array($path2, str_replace(EXT, '', $name), str_replace('/','', $path));

//with this
return array($path2, str_replace(EXT, '', $name), substr($path, 0, -1));
[/quote]

Yep, that works. Thanks!




Theme © iAndrew 2016 - Forum software by © MyBB