PyroCMS is built with CodeIgniter PHP framework. CodeIgniter is one of the popular PHP frameworks preferred by many developers around the world. PyroCMS has greatly reduced efforts of CodeIgniter developers by automating and including most common things a web application should have. Not only developers but also normal users are now able to easily install the CMS.
Additions to PyroCMS Module
PyroCMS Module is almost similar to CodeIgniter application with few additions. If you have ever tried creating application with CodeIgniter, these things are very easy to understand and create new modules.
details.php
This file is responsible for providing necessary information about the module. It is kept at the same level as of models, controllers, views folders.
Admin_Controller, Public_Controller
In CodeIgniter you have only CI_Controller, but in PyroCMS you have four controllers, namely, Admin_Controller, Public_Controller, My_Controller and CI_Controller. If you are inheriting Admin_Controller, the content will be available only to logged in users in backend (control panel) and if you inherit your class from Public_Controller, it will be available to users not logged in. My_Controller already enhanced class to suit PyroCMS needs. And of course there is CI_Controller that you can use if you wish.
css, js, img folders
Because each module needs different views, hence different assets (css, js, img). You can now directly have three folders css, js, img at the same level as controller, models, view folder. And you don’t have to worry much about using them. You can use them in your controllers in two easy steps:
- Template::append_metadata()In PyroCMS you will be using template library. When you wish to add extra CSS or JavaScript file, you have to use append_metadata() function
- css(), js(), etc.Inside append_metadata, you can take help of functions in asset helper (
system/cms/helpers/asset_helper.php) to add extra css or javascript file. To know about these functions in details visit PyroCMS APIpage and search for above function names.$this->template ->append_metadata( css('blog.css', 'blog') ) ->append_metadata( js('custom.js', 'blog') ) ->build('admin/index', $this->data);
Understanding details.php file structure
Have a look at following code of details.phpfile and try to understand what’s said in comments. It will quickly let you understand what to do.
<?php defined('BASEPATH') or exit('No direct script access allowed');
class Module_Blog extends Module {
public $version = '2.0';
public function info() {
// Returns array
}
public function install()
{
// Returns boolean
}
public function uninstall()
{
// Returns boolean
}
public function upgrade($old_version)
{
// return boolean
}
public function help()
{
// some string
}
}
/* End of file details.php */Class Name
In PyroCMS, when you are creating a new module, class name in details.php file must begin with Module_ followed by module name, and must extend class Module
Version
Version number is for identifying the changes being done in plugin. It help developers to create upgrade login.
function info()
This is probably the most important function in any module. This function returns an array of elements that are discussed further.
return array( 'name' => array( 'en' => 'Blog', ), 'description' => array( 'en' => 'Post blog entries.', ), 'frontend' => TRUE, 'backend' => TRUE, 'skip_xss' => TRUE, 'menu' => 'content', 'roles' => array( 'put_live', 'edit_live', 'delete_live' ) );
- name : It contains a two dimensional array whose keys are language code and values are names of module in corresponding language.
- description: Similar to name, description is also two dimensional array written in similar fashion as name element
- frontend: It takes boolean value, tells module will be available in frontend or not
- backend: Similar to frontend, it tell wheter module will be available in backend or not
- skip_xss: Takes boolean value
- menu: The menu group in which your module will appear. You can choose from content, design, users, utilities or FALSE. Here if you want to create your own menu group, just add
menu => 'mygroupname'. Note that these names are only for reference, only module names will appear in the menu. Also that if you have only one module in specific group, module will appear as main menu and not as sub-menu. - roles: its a one dimensional array used for user permissions to access certain functions. You can use
role_or_die()function to check the permissions.
function install()
In this function you need to add installation logic. Typically it includes creating tables into database. You can use functions like $this->db->query($my_query) to create tables.
function uninstall()
You have uninstall logic here. If you added some tables while installing the module, you might want to drop those tables here.
function upgrade()
You can have your upgrade logic here. Remember that all the information of installed module is available to you from $this->module_details array.
function help()
Finally, in this function you can return some text that will appear as help when user clicks help icon in control panel.
What Next?
Now you understood how to create details.php file of PyroCMS module. In the next part you will be introduced to creating Controllers and PyroCMS template library.


