-
Notifications
You must be signed in to change notification settings - Fork 0
Matchbox
[b]Current version:[/b] File:Matchbox-0.98.zip [b]Forum Thread:[/b] [url]http://codeigniter.com/forums/viewthread/65749/[/url] [b]Last update:[/b] 2009-09-02
Matchbox is a set of extended libraries that lets you organize your application in small components (modules). These modules have several advantages, the main one being portability. Modules are stored in their own folders and so they can be reused in other applications or shared between users by copying just that one folder.
[h3]Installation[/h3] If you can run CodeIgniter, you've already met the server requirements, thus all you have to do is download and unzip the latest version of Matchbox right into your application directory. File:Matchbox-0.98.zip
To test your installation, open up your browser and test the uri [b]http://yoursite.com/pathto/index.php/matchbox/[/b].
If you see the Matchbox dashboard, you've successfully installed Matchbox!
If it's not working see [b]Troubleshooting[/b] further down this page, or if that doesn't answer your questions, ask them in the [url=argh]forum thread[/url].
[h3]Usage[/h3] Installing Matchbox won't effect your current application, though. Any controllers in the [b]APPPATH/controllers/[/b] will work like they used to. To start modulizing your application you have to create a module.
[h4]Creating a module[/h4] To make a new module, you create a new folder in the [b]APPPATH/modules/[/b] directory. For instance, creating the directory [b]APPPATH/modules/my_new_module/[/b] results in a new module named 'my_new_module'.
Within this folder you place additional folders for each type of resource you need in the module. Often you'll want controllers in your module, in which case you make a 'controllers' folder in your module directory. You can also add folders for config files, helpers, languages, libraries, models, plugins and views. Your module folder should like a lot like your application directory.
[h4]Controllers in modules[/h4] So you've got a module directory with a [b]controllers/[/b] folder, and now you want to make a controller to place there. Luckily, module controllers are no different from regular controllers, so if you want to test Matchbox right away, you can go ahead and copy one of your exsisting controllers to your module (or just create a new one).
To access your controller, you go to [b]http://example.com/index.php/MODULE-NAME/CONTROLLER-NAME/[/b]. Basically the only difference from accessing a regular controller, is that you have to add the module name before the controller name in the uri. If you only type in [b]http://example.com/index.php/MODULE-NAME/[/b] and not the controller name, Matchbox will try to load the controller with the same name as the module (unless [b]strict mode[/b] is enabled, which is explained futher down the page).
[h5]Resources in modules[/h5] Where things start to get interesting, is when you need to load resources like helpers from your controllers. If the resource is located in the same module or in your application directory, they can be loaded as usual (unless [b]strict mode[/b] is enabled, which is explained futher down the page).
However, if you need to load resource from another module than the one the controller resides in you'll have to tell Matchbox what module to look inside. You do this by either adding the module name as the last argument when using regular load calls. [code]$this->load->model('blog_model', '', FALSE, 'my_other_module');[/code] Or alternatively, you can prefix the load call with 'module_', in which case the module name is the first argument. [code]$this->load->module_model('my_other_module', 'blog_model');[/code]
[h4]Caller Detection[/h4]