ExpressionEngine

2.11.9 User Guide

Retired Documentation

You are using the documentation for version 2.11.9. Go here for the latest version or check here for your available upgrades to the latest version.

Module Conversion Walk-through

  1. Create Update File
  2. Modify Language File
  3. Modify Core Module File (mod.package_name.php)
  4. Create View Files (Optional)
  5. Modify Control Panel File (mcp.package_name.php)

Create Update File

Every module must have a upd.package_name.php with at least three methods: install(), uninistall(), update().

  1. Copy your mcp.package_name.php file and rename it upd.package_name.php

  2. Rename class upd.package_name.php to Package_name_upd and constructor to __construct()

  3. Remove all methods except module_install(), module_deinstall(), any upgrade method, and any dependencies

  4. Rename the methods: module_installinstall, module_deinstalluninstall.

  5. Make sure you have a method named update and that it accepts one argument $current, which will be the current installed version of the module in the database:

    function update($current = '')
    
  6. Convert any relevant syntax to the new format.

  7. Make certain your queries are converted to use active record or database forge (for database manipulation).

  8. Save, you’re done with your update file!

Note

If your module requires user input to complete the install, that should occur on first-run of the module control panel, and not the primary installer. This allows your module to be installed during the ExpressionEngine installer process. See the Wiki module for an example if needed.

Modify Language File

  1. The lang.package_name.php file must be renamed package_name_lang.php.
  2. Rename the $L array containing language variables to $lang.

Modify Core Module File (mod.package_name.php)

Converting the mod.package_name.php file is simply a matter of altering the existing syntax. See the syntax conversion notes for more detail. Don’t forget to:

Modify Control Panel File (mcp.package_name.php)

The control panel uses an MVC development approach, and your module can take advantage of this by using view files instead of creating your markup in your controller. If you’ve never worked with MVC or view files before, please read the overview of views in the CodeIgniter user guide.

View files for your module will reside within a folder named views within your module’s folder. ExpressionEngine will automatically look in that path to find your view files, allowing you to use them thusly:

return ee()->load->view('index', $vars, TRUE);

Note in the above example that the third argument of view() is being used so that instead of being added to existing output, it is returned as a string, and that the value is being returned by the method. In this example, the view file named index.php in the module’s views folder would be loaded, and variables are supplied to it via the $vars array.

If for some reason you do not wish to use views, you can still build your output directly in the controller method and return it as a string. In fact, you are still returning a string when you use view files, but it is an easier to edit and more organized developmental strategy.

  1. Rename class and constructor to use _mcp suffix instead of _CP.

  2. Convert your syntax

  3. Remove the deprecated Display class

  4. Specify a few cp variables in each method that is accessed directly. You need to set the page title (cp_page_title variable) and the base breadcrumb link using this format:

    ee()->cp->set_breadcrumb(BASE.AMP.'C=addons_modules'.AMP.'M=show_module_cp'.AMP.'module=package_name', lang('package_name_module_name'));
    ee()->view->cp_page_title = lang('package_name_module_name');
    
  5. If the method is loading a view, load any dependences (such as the table class or form helper) before loading the view:

    ee()->load->library('table');
    ee()->load->helper('form');
    
  6. If you are using jQuery in your control panel, initialize and compile it in your controller before loading your view or returning your string.

  7. If you are loading a view file, be certain all variables needed for display are defined in the $vars array. Array keys will correspond to the variable name in the view file.

  8. Pass those variables to the appropriate view via:

    return ee()->load->view('view_filename', $vars, TRUE);
    
  9. Celebrate, you’re done!