Part of the EllisLab Network
   
1 of 35
1
Matchbox 0.9.4
Posted: 25 November 2007 01:24 PM   [ Ignore ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  489
Joined  06-16-2006

(Matchbox is the successor of Modular Separation. However, Matchbox is backwards compatible with its predecessor so you can switch over without problems)

Matchbox is a set of extended libraries for CodeIgniter that lets you organize your application in modules. A module is a self-contained component of your application and can contain an arbitrary number of resources of any kind (controllers, libraries, views, etc.). Modularity have several purposes, the first being helping you neatly organize your application. As sites increases in size, resource folders tend to become bloated and confusing to navigate. Using modules you can break your application into smaller components that are easier to manage. Secondly, if you should ever need to reuse a component in another application you don’t have to search for every resource required by the component since you have already stored them in one directory and so you only have to copy one folder. Lastly there are the ready-made downloadable modules that can be installed by simply dropping its folder in your application and firing up the module.

You can find downloads and a comprehensive documentation at matchbox.googlecode.com.

Please feel free ask questions and post feedback in this topic.

If you have ideas or suggestions, in order to avoid this thread becoming too messy, I encourage you to post them to the Matchbox Development Google Group (http://groups.google.com/group/matchbox-development). That way I can look on each suggestion separately.

Quick Documentation
(Comprehensive documentation avaiable at http://matchbox.googlecode.com)

Have It Your Way Then
Before you get your hands dirty you have to decide where to store your modules. You will most likely want to store them in /application/modules (which is the standard setting), however this is configurable. In the configuration file there is an array, $config[’directories’] with just one item, ‘modules’. This array contains paths *relative* your application folder in which to look for modules. You can add as many paths as you like, however the more you add, the more searches will be made with each page view. Also note that the searches are performed in the order of the array.

When you are done configuring the module directories, do remember to create them.

Mastering the Directory Structure
Modules have a strict folder structure and it is important that you adhere to this when developing. Here is an example.

- modules (1)
  -
example (2)
    -
controllers (3)
        
example.php
    
- libraries (3)
        
examplelib.php
    
- views (3)
        
example_view.php

1. The modules folder - Is the parent of any modules you create. Can be any of the directories configured in the previous step.
2. The name of your module - Contains all the resources for this particular module. The name is restricted to letters, numbers, and the characters {{{~%.:_-}}}.
3. Resource folders - Are the same folders you find in your application directory (helpers, models, etc.). You only need to create folders for the types of resource that you need.

Controllers? Controllers!
The controllers themselves work like they always have. However, the way you store and access them are slightly different. At its simplest this is how it works.

www.example.com/module/controller/method/parameter

1. The first segment represents the module in which the controller can be found.
2. The second segment represents the controller that should be invoked.
3. The third segment represents the method that should be called.
4. The fourth, and any additional segments, represents the variables that will be passed to the controller.

As you may have noticed the only difference from the standard style is the module segment in front. There are two exceptions, though.

1. If the controller is located in a subfolder then the subfolder must be added as another segment between the module and controller segments.
2. If the controller have the same name as the module, the controller segment can be omitted.
3. If the controller is in a subfolder and have the same name as the subfolder, the controller segment can be omitted.

Them There Resources
The process of loading resources will do all the thinking for you. When you try to load something, the resource will be looked for in the module in which the current controller reside and, failing that, in the resource folders in your application directory and then the system directory. If the controller is in the standard folder, then the module checking will simply be skipped. However, you might want to load resources from other modules (side-wide authentication resources for instance) and if that is the case you have two options.

1. Every method of the Loader library (that loads resources) have been extended with an additional parameter, a module name. So you simply put the name of the module with the desired resource after the standard parameters.
2. Due to the often unused last few parameters of the loading methods, you also have the option to use alternative methods that are exactly the same as the standard ones, except for the added prefix “module_” and that the module parameter is the first one (e.g. instead of $this->load->view(’file_name’, false, false, ‘module’) you would go with $this->load->module_view(’module’, ‘file_name’)).

If you wish to autoload a resource that is located in a module, you will have to tell the autoloader where to look. This is done by adding a key to the array items that are in modules. You can still autoload resource that are not in modules. Here is an example.

$autoload['libraries'] = array('database', 'session', 'module_name' => 'library_name');

 Signature 

Best regards, Zacharias.
Matchbox - Modular Separation | Wick - Controller Loader

Profile
 
 
Posted: 25 November 2007 02:02 PM   [ Ignore ]   [ # 1 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  660
Joined  06-07-2007

“Matchbox is a set of extended libraries for CodeIgniter”
Does that mean you can bundle this with a CI installation just by adding the libraries? i.e. no core manipulation.

 Signature 

CodeExtinguisher
Download: codex2_rc14.2.zip - 219 KiloBytes of Gloriousness!
Demo: Public preview - login with preview:preview
Temporary Docs: PBWiki

Profile
 
 
Posted: 25 November 2007 03:00 PM   [ Ignore ]   [ # 2 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  489
Joined  06-16-2006

Exactly. smile

 Signature 

Best regards, Zacharias.
Matchbox - Modular Separation | Wick - Controller Loader

Profile
 
 
Posted: 25 November 2007 04:06 PM   [ Ignore ]   [ # 3 ]  
Research Assistant
RankRankRank
Total Posts:  903
Joined  07-10-2006

If Module Manager was released as a module, it could be considered optional and an independent download.

Profile
 
 
Posted: 25 November 2007 04:24 PM   [ Ignore ]   [ # 4 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  489
Joined  06-16-2006

Yes, that would seem the most logical solution. However, that would mean users would have to not only distinguish module and standard CI contributions, but also modules with and without requirement for the module manager. But that might not be that big a deal…

 Signature 

Best regards, Zacharias.
Matchbox - Modular Separation | Wick - Controller Loader

Profile
 
 
Posted: 25 November 2007 04:25 PM   [ Ignore ]   [ # 5 ]  
Grad Student
Rank
Total Posts:  86
Joined  08-23-2007

Congratulations Zacharias! A great tool now also has a great name wink

Do you guys feel a Module Manager is a worthy addition, and if so, what features would you like to see implemented?

It would be handy to have at least an example on how to build such a module-manager. And if you were to take it to extremes it would of course be great if the module-manager would contain zip-upload, so users can easily add modules through a web-based admin panel. But I don’t know if you were thinking along those lines.

A question though: I read that in Matchbox 0.9 modules can be placed in application/ or system/, but would it also be possible to place the modules-folder in the BASE_PATH of CI? So the same place where the main index.php resides? Or would I have to hack into Matchbox to achieve that?

Profile
 
 
Posted: 25 November 2007 04:30 PM   [ Ignore ]   [ # 6 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  489
Joined  06-16-2006

Thanks, I fond of the name as well ^^

A full-fledged module manager with downloadable modules have crossed my mind, yes. What do others think?

Regarding the BASE_PATH, the BASE_PATH is in fact your /system folder. But if you wish to place it where your index.php reside I would like to ask: why? smile

 Signature 

Best regards, Zacharias.
Matchbox - Modular Separation | Wick - Controller Loader

Profile
 
 
Posted: 25 November 2007 05:00 PM   [ Ignore ]   [ # 7 ]  
Grad Student
Rank
Total Posts:  86
Joined  08-23-2007

Regarding the BASE_PATH, the BASE_PATH is in fact your /system folder.

Sorry, I meant base_url.

But if you wish to place it where your index.php reside I would like to ask: why?

I thought you’d never ask wink The reason for this is that I develop open-source software, and I want to make the software as easy to use as possible for non-technical people. This is also reflected in the directory-structure: everything that should be easily accessible to users, is in a seperate folder called /user-content/: layout themes, widgets, config, etc. Another benefit of this approach is that users can upgrade to the latest version of my app, without overwriting any changes they made to their themes, config files, etc.

I’ve also created an architecture for widgets, which are basically mini-CRUD “modules”, which can be dragged around and placed anywhere in the layout. I don’t have a zip-installer for widgets, so I thought it would be easy to also place the widgets-folder inside that user-content folder for easy-accessibility.

Anyway, a zip-uploader for modules would solve this “issue” in an even user-friendlier way, so I opt for that one!

Profile
 
 
Posted: 25 November 2007 05:05 PM   [ Ignore ]   [ # 8 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  489
Joined  06-16-2006

Well if it is just for user-friendlynes I think I’d rather go with the module manger. The resource locater already looks in quite a few places. However, I’d still like to hear peoples thought on what features one such manager should include.

(I’ll still have a look at how one might go on about having it look at the base url smile)

EDIT: One thing you should note about having modules in the base url (root) or any other place than in the APPPATH. Controllers won’t work. So if you want to use modules with controllers (which I assume you do) you have to have them in your application folder. However, modules just containing helpers, libraries, etc. can go in BASEPATH.

 Signature 

Best regards, Zacharias.
Matchbox - Modular Separation | Wick - Controller Loader

Profile
 
 
Posted: 25 November 2007 05:34 PM   [ Ignore ]   [ # 9 ]  
Sr. Research Associate
RankRankRankRankRank
Total Posts:  2858
Joined  07-14-2006

Great stuff, I really like the direction you are going with it.

What would be the scope of the module manager would it handle set up/removing module related database tables. As for the interface it would have some form of authentication procedure i guess so will it be build in or would it be up to the developer to implement it?

Profile
 
 
Posted: 25 November 2007 05:49 PM   [ Ignore ]   [ # 10 ]  
Grad Student
Rank
Total Posts:  86
Joined  08-23-2007

EDIT: One thing you should note about having modules in the base url (root) or any other place than in the APPPATH. Controllers won’t work. So if you want to use modules with controllers (which I assume you do) you have to have them in your application folder. However, modules just containing helpers, libraries, etc. can go in BASEPATH.

Ok, that’s very useful information smile Thanks! If this is the case I’m even more in favor of a module-installer. Though I think it might be hard to make one that fits in with everyone’s application: user-management, menu-system, etc. I think you should start simple: just an interface to upload or delete modules. Maybe activate/de-activate too, and users can adjust it to their own application/needs.

Profile
 
 
   
1 of 35
1
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 719, on June 06, 2008 10:16 AM
Total Registered Members: 61073 Total Logged-in Users: 10
Total Topics: 73897 Total Anonymous Users: 3
Total Replies: 398568 Total Guests: 325
Total Posts: 472465    
Members ( View Memberlist )