Knowledge Base
Knowledge Base
Glossary
Glossary
Videos
Videos
Community Forums
Forums
Bug Reporting
Bug Reports
Search KB
Search KB

Modules

68KB comes with a module system that allows you to extend the script without hacking any core files.

Requirements

  1. Each module must be contained in a single directory.
  2. Each module must have a config.php file that includes needed information.
  3. The users should be able to activate and use the module from the "Modules" menu in the administrative. Optimally, a module should not require users to modify the source code.
  4. If the module is going to interact with 68KB events system it must contain a file events.php and the class must be named with the module name underscore events. For example: class mymodule_events is a valid class name where class mymodule() is not. If you name your class incorrectly it will not cause problems except it will never be called through the script.
  5. If needed inside the modules directory it can have a templates and language directory. The templates directory would contain any template files needed. The language directory allows your module to work for multiple language.
  6. index.php and admin.php and used if the module has a frontend area or an administration section. These are only required if the user needs to have some of interaction with the module.
  7. You may include any other files that the module may need to enteract with.

Setup

All modules are required to have at the very minimum a config.php file. Other files which can be included and used by the script are init.php, events.php, admin.php, and index.php

config.php

All modules need to have a config.php file. This file basically tells the system about your module. Below is a copy of the file

<?php
$data['module']['name'] = "modulename";
$data['module']['displayname'] = "Display Name";
$data['module']['description'] = 'Description of the module';
$data['module']['version'] = "1.0.0";
?>

These variables should be pretty self explanatory. However the name should only contain letters, numbers, dashes, or hyphens. Do not enter any spaces here. The version is your internal version number seperate from 68KB.

init.php

The init.php file is responsible for making any database changes. If used this file should include two functions: install() and uninstall().

events.php

The events.php file is used to interact with the core script. If used this file should include a class named with the module name an underscore and events.

For example if your config file has this:

$data['module']['name'] = 'niftymodule'; 
then you would name the class niftymodule_events.

Here is an example file:

class niftymodule_events
{
	function niftymodule_events(&$kb_events)
	{
		$kb_events->register('template/header', $this, 'my_header');
		$kb_events->register('admin/template/nav/settings', $this, 'template_link');
	}
	function my_header()
	{
		echo 'This is a test';
	}
	function template_link()
	{
		$link = '<a href="'.site_url('admin/modules/show/niftymodule/').'">Test Link</a>';
		echo $link;
	}
}

As you can see we name the class like outlined above. Next we create a constructor with the same name. (Our script is designed to work with PHP 4 so it must be named the same.)

Next inside the constructor we pass &kb_events by reference. Inside we register any events that our module will interact with. In this case when template/header is called we want to run the method my_header which just echos test.

admin.php

The admin.php file is a file that can be accessed through the administration. This is useful if you need to get some type of data from the administrator. As you can see in the events file above we add a link to the admin template which will show the admin file.

In order to use the internal system (to access models, helpers, etc.) you should enter

$CI =& get_instance();
and then use
$CI->load->model('articles_model');
to load what you need.

index.php

The index.php file is just like the admin.php except it used for the sites frontend.

Events

The script has a lot of events and the best way to find them would be to search for:

$this->kb_events->trigger
However here is a list of the most notable.

articles/add

This is called when an article is added an array of the article data is passed.

articles/edit

This is called when an article is edited an array of the article data is passed.

articles/delete

This is called when an article is deleteed the article id is passed.

categories/add

This is called when a category is added an array of category data is passed.

categories/edit

This is called when a category is edited an array of category data is passed.

categories/delete

This is called when a category is deleteed the category id is passed.

template/header

This is called in the front end layout template. It could be used to add extra detail to the header

template/footer

This is called in the front end layout template. It could be used to add extra detail to the footer