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¶
- Create Update File
- Modify Language File
- Modify Core Module File (mod.package_name.php)
- Create View Files (Optional)
- 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()
.
Copy your
mcp.package_name.php
file and rename itupd.package_name.php
Rename class
upd.package_name.php
toPackage_name_upd
and constructor to__construct()
Remove all methods except
module_install()
,module_deinstall()
, any upgrade method, and any dependenciesRename the methods:
module_install
→install
,module_deinstall
→uninstall
.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 = '')
Convert any relevant syntax to the new format.
Make certain your queries are converted to use active record or database forge (for database manipulation).
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¶
- The
lang.package_name.php
file must be renamedpackage_name_lang.php
. - 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:
- Call the super object
- Switch to active record for your queries
- Take advantage of the new Template variable parser
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.
Rename class and constructor to use
_mcp
suffix instead of_CP
.Convert your syntax
Remove the deprecated Display class
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');
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');
If you are using jQuery in your control panel, initialize and compile it in your controller before loading your view or returning your string.
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.Pass those variables to the appropriate view via:
return ee()->load->view('view_filename', $vars, TRUE);
Celebrate, you’re done!