Skip to content
World Wide Web Server edited this page Jul 4, 2012 · 85 revisions

[b]Current version:[/b] File:Modular_Separation_2.4.1.zip [b]Forum Thread:[/b] [url]http://codeigniter.com/forums/viewthread/46669/[/url] [b]Last update:[/b] 08-09-2007

This is a solution for people that are looking for a way to keep associated models, views, controllers and other resources in the same directory and thereby making their application more modular.

[h2]Installation[/h2] First of all you should go ahead and grab yourself a copy of the File:Modular_Separation_2.4.1.zip.

When you are done grabbing, you should place all the files in your [i]/application/libraries/[/i] folder.

Finally, you must create the directory [i]/modules/[/i] in your [i]/application/[/i] folder.

And that's it! sound of party blowers

[h3]... Unless you are running PHP 4[/h3] In which case you will have to use File:Modular_Separation_PHP4.zip. Download it and overwrite the original in your [i]/codeigniter/[/i] folder.

[h2]Folder structure[/h2] I would like to start with pointing out that you are still able to use models, views, controllers and other resources as usual when using Modular Separation. This also means that you can have global resources in your standard folders and call them from your modules. If you, on the other hand, want to get rid of the folders then you are free to do so, [b]with the exception of the controllers folder[/b].

Modules must be placed in the /application/modules/ folder. A module is a folder (the foldername is the name of the module) containing folders for models, views, controllers and other resources. These are not required and you do not have to add folders for e.g. models if you are not including any models in the module.

Just to make sure we are clear on the folderstructure, he is an example: [code] system application modules account controllers account.php libraries my_generic_authlib.php models user_model.php views login.php register.php news controllers news.php models news_model.php views list.php categories.php [/code]

[h2]Usage[/h2] Now, all you have to do in order to load a resource from the current module, is, well, what you have always done. CodeIgniter will automaticly look for the requested resource in your module folder first.

But what if the resource is located in another module, you may ask? Simply, add its name as the last argument of one of the loader methods and that will do the trick. But since most of those methods have additional arguments that are not commonly used, I have also made special module-methods where the name of the module is the first argument (following by all the standard arguments). The following methods have been added: [h3]$this->load->module_library() $this->load->module_model() $this->load->module_view() $this->load->module_file() $this->load->module_helper() $this->load->module_plugin() $this->load->module_language() $this->load->module_config()[/h3]

Now, two of the above is just aliases, so I've also added these two: [h3]$this->lang->module_load() $this->config->module_load()[/h3]

[h2]Autoloading of configuration[/h2] Whenever a module is requested, CodeIgniter will look for a config file with the name of your module and the suffix _lang.php. First in the module folder's config-directoy, and, failing that, in the global application config folder.

Clone this wiki locally