Creating a module

PyroCMS is built to be modular, so creating modules is a pretty simple process. There are two kinds of module: "core" and "third_party". A core module is something the system can't function without, or is considered pretty important. A third-party module is something that is optional that can be deleted or added with no effect to the site. Any module you create should ideally go into application/modules/third_party/.

Each module can contain the following directories: config, controllers, helpers, libraries, models, views, js, css, img. If a module will have a frontend (something that displays to the user) then it should contain at least one controller, and that controller should be the same name as the module.

E.g: application/modules/third_party/news/controllers/news.php

The rest of it is pretty much normal CodeIgniter development except for a few things.

details.xml

Each module contains a details.xml file which contains its name, description, version, wether they are available to the backend and/or frontend, etc.

<?xml version="1.0" encoding="UTF-8"?>
<module version="0.7">
    <name>
        <en>News</en>
        <es>Artículos</es>
        <fr>Actualités</fr>
        <de>News</de>
    </name>
    <description>
        <en>Post news articles and blog entries.</en>
        <es>Escribe entradas para los artículos y blogs (web log).</es>
        <fr>Envoyez de nouveaux articles et messages de blog.</fr>
        <de>Veröffentliche neue Artikel und Blog-Einträge</de>
    </description>
    <is_frontend>1</is_frontend>
    <is_backend>1</is_backend>
    <is_backend_menu>1</is_backend_menu>
    <controllers>
        <controller name="admin">
            <method>index</method>
            <method>create</method>
            <method>edit</method>
            <method>delete</method>
        </controller>
    </controllers>
</module>

Public Controllers

In normal CodeIgniter there is only one controller class. In PyroCMS there are four. Controller, MY_Controller, Admin_Controller and Public_Controller. To use one of these you can extend them like so:

<?php

class Modulename extends Public_Controller {

    function __construct() {
        parent::Public_Controller();
    }

    function index()
    {
        echo "Hello world";
    }
 
}

?>

This page will be available to anyone wether logged in or not and will use the frontend design. That means it will use the current active theme and show any login data and navigation, etc and can be viewed via "http://example.com/modulename".

Admin Controllers

Admin controllers have a few different properties to them. It will automatically check that a user has permission to be there, and redirect them to a login page if not. This means they either need to have a user role of "admin" or be allowed specific permissions on the controller or module.

application/modules/modulename/controllers/admin.php

<?php

class Admin extends Admin_Controller {

    function __construct() {
        parent::Admin_Controller();
    }

    function index()
    {
        echo "Hello admin";
    }
 
}

?>

This page can be accessed via "http://example.com/admin/modulename".

Clearing the cache

When you put together your module structure and made your details.xml file, you might notice there is still no sign of your module in the admin panel. The navigation is cached to save CPU cycles as parsing 10+ XML files on each page load is silly. To get your backend module to appear (if you have told it to do so with is_backend_menu in details.xml) you need to clear the application/cache/modules_m/ cache folder like so:

sudo rm -rf application/cache/modules_m

Now your module should appear and you can start developing your module using normal CodeIgniter methods, your own libraries and those included with PyroCMS.