Welcome Guest, Not a member yet? Register   Sign In
CICON2010 - Modular CI
#11

[eluser]gyo[/eluser]
Actually I wasn't sure if 'modules' were intended to be separate from the main CI application, or better stand-alone. Now it makes sense. Smile

What I mean is that with URI routing, the whole story would even be more flexible and interesting.
And a developer can use it or not, depending on the needs.


What do you think?
#12

[eluser]Dan Horrigan[/eluser]
WanWizard,

Nice concept I am working on something similar for Pancake (http://pancakeapp.com). We are going to be using a combo of modules and packages in a very unique way. MAY open source it...not sure yet.

Anyway, why are you using the _assign_libraries() function? Why not use a __get()?

EDIT: Nevermind...i see you are already using __get for loading the libraries.

Dan
#13

[eluser]WanWizard[/eluser]
[quote author="gyo / suashi" date="1282146658"]What I mean is that with URI routing, the whole story would even be more flexible and interesting.
And a developer can use it or not, depending on the needs.

What do you think?[/quote]
Possible, but that whould either mean a major rewrite of the CI core code, massive hook 'work', or using a fixed controller, and do the routing in there. I have to think about something clever that doesn't need major CI modifications...

If you have a URI like "/sectionA/sectionB/sectionC/sectionD/sectionE", you could have:
1) sectionA is a controller, section B is a method, the rest are URI segments
2) sectionA is a controller folder, section B is a controller, sectionC is a method, the rest are URI segments
3) sectionA is a module, section B is a controller, sectionC is a method, the rest are URI segments
4) sectionA is a module, section B is a controller folder, sectionC is a controller, sectionD is a method, the rest are URI segments

Routing should be able to handle all these situations, and also deal with duplicates properly. For example, if in a standard CI installation you have a controller called "Test", and you have a controller folder called "Test", nothing in that folder is accessable because CI checks for a controller first. Preferrably it should check from situation 4) to 1), to allow all possibilities.

I'll have a look, first a conversion into using $this->load->module() (seems more natural to use this), and support for language files (forgot that).
#14

[eluser]WanWizard[/eluser]
New version is available (funny, now uploading works again).

Modifications:
- modules live by default in the application folder
* can be altered by calling $this->load->module_path();

- modules are now loaded via $this->load->module()
* this requires a MY_Loader extension, merge it if you already have one.

- as per request: you can now route to module controllers
* no code modification, requires only adding a route to config/routes.php!

Code:
// you can choose to route all your standard application controllers first
// and everything else to the module router
$route['(welcome|test)(.*)'] = '$1$2';    // welcome.php and test.php are application controllers
$route['(.*)'] = 'route2module';        // everything else is assumed to be a module

// you can also route on a per-module basis
$route['modulename(.*)'] = 'route2module';        // only do module routing for this module

- when using routing, controllers now support the _remap() method

There is an example module included, and a Test controller to test the module functionality.

The URL http://example.org/example/example_contr.../varY/varZ will route to the controller example_controller in the example module (will call _remap(), since it exists. Remove it to test calling a method).

The URL http://example.org/test should output:
Quote:Calling: $this->example->library->example_library->example('varA', 'varB');

Example_library constructed.

Welcome from the module 'Example', library 'example_library', method 'example'.

array
0 => string 'varA' (length=4)
1 => string 'varB' (length=4)

Calling: $this->example->model->example_model->example('var1', 'var2');

Example_model constructed.

Welcome from the module 'Example', model 'example_model', method 'example'.

array
0 => string 'var1' (length=4)
1 => string 'var2' (length=4)

Calling: $this->example->controller->example_controller->example('varX', 'varY', 'varZ');

Example controller constructed.

Welcome from the module 'Example', controller 'example_controller', method example!

array
0 => string 'varX' (length=4)
1 => string 'varY' (length=4)
2 => string 'varZ' (length=4)

Calling: $this->example->view('example')

We've got ourselfs an example view!

Calling: $this->example->helper('example');
Calling: Calling: example();


This is the example helper, loaded from the example module.

Calling: $this->example->lang('example');
Calling: $this->lang->line('example_language');


String from the example language file.
#15

[eluser]Mark Croxton[/eluser]
This is really clever stuff. Great work!
#16

[eluser]WanWizard[/eluser]
It suddenly dawned to me that there wasn't a lot of specific 2.0 code in here, so I made it work in 1.7.2 as well...
#17

[eluser]gyo[/eluser]
HOT!! I just love the routing solution, thanks man! Wink
#18

[eluser]WanWizard[/eluser]
Moved this solution to the Wiki.

A new version of Modular CI is now available for download from the Wiki. This version introduces full routing support for module controller, using standard CI routing rules, and without any restriction to the format of your rules.

If you like to discuss this solution, if you have comments or feature requests, please start a wiki discussion!
#19

[eluser]eokorie[/eluser]
This sounds like a great solution for some of the issues I have encountered with other modular plugins for CI. Will this also support config files in modules?

Great job by the way!
#20

[eluser]Jônatan fróes[/eluser]
You're doing a great work... I'll try it today!




Theme © iAndrew 2016 - Forum software by © MyBB