Creating a module in Ionize

part 1 : Introduction

tuesday 18 may 2010 at 22h38 • categories : How to

What's a module ?

A module extends Ionize and the built on website and provides new functionalities. In a way, it can be see as a CodeIgniter little application designed to work with Ionize.

A module :

  • have an admin part and a front-end part, or just one of them,
  • can store data in dedicated tables, if these tables are defined in the installation file,
  • has its own controllers, models, and views. It can use Ionize's libraries and models,
  • can have its own tags.

Folders organization

Each module has its own folder stored in the /modules folder. In the given example, these folders are located in /modules/EmailRecord/.

The module folder structure is close to one CodeIgniter application folder.

Ionize's one module folder

config/ Module configuration files. config/config.php : Stores modules dedicated configuration variables.
config/routes.php : The module route config file.
This file is mandatory in order to have a working module.
controllers/ controllers/my_module.php : The front-end controller
controllers/admin/my_module.php : The backend controller
languages/ Contains the languages translation files, grouped by language code folder.
libraries/ Contains the module optional libraries
models/ Module's models
views/ Module's views views/admin/ : Contains the module's admin panel views

Make a module installable

Installation / uninstallation takes place in the Modules > Administration menu of Ionize.

To be installable and to work, each module must have one config.xml file, stored at the root folder of the module's folder.

Module's configuration : config.xml & config.php

The config.xml file describe the module, make it installable but also define the module tables (if the module needs tables).
One module can of course have more than one table.

Example of config.xml :

<?xml version="1.0" encoding="UTF-8"?> <module> <name>Module name</name> <description>Module description</description> <uri_segment>default_uri_segment</uri_segment> <has_admin>true</has_admin> <database> <table name="module_emailrecord_emails" if_not_exists="true" engine="InnoDB" default_charset="utf8" collate="utf8_unicode_ci" auto_increment="1"> <primary_key>id_email</primary_key> <column name="id_email" type="int" length="11" attributes="UNSIGNED" zerofill="NOT NULL" auto_increment="true" > </column> <column name="email" type="varchar" length="255"> </column> <column name="name" type="varchar" length="255"> </column> <column name="join_date" type="datetime" zerofill="NOT NULL"> </column> <column name="ip" type="varchar" length="15"> </column> <column name="confirmed" type="tinyint" length="1" default="0"> </column> </table> </database> </module>

The config.php file

Folder : modules/my_module/config/

This file gives the default URL to the module. the only line to change is $route[default_controller], which should take the name of your module's main controller.

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); // ONLY THIS LINE HAS TO BE MODIFIED $route['default_controller'] = "search"; // search/function $route['(.*)'] = $route['default_controller'].'/$1'; // search => search/index $route[''] = $route['default_controller'].'/index';

Module Front-end controller

Each module can have a front-end controller, which is the “website side” controller.

Folder : modules/my_module/controller/

This controller must be named as the module folder, without hyphenated chars.

It must also extend Base_Controller

Module Administration controller

The module administration controller will display the module's Ionize panel.

Folder : modules/my_module/admin.

Must be named as the module folder name, without caps letters.

Must extend Module_Admin


Models can extend base_model, but it's not mandatory.

Languages translations

Languages translation files are used to store static translated text.

Folder : modules/my_module/language/xxx/

File name : <my_module>_lang.php