Path

ezpublish / documentation / tutorials / developing ez publish exten... / creating a new extension


Caution: This documentation is for eZ Publish legacy, from version 3.x to 6.x.
For 5.x documentation covering Platform see eZ Documentation Center, for difference between legacy and Platform see 5.x Architecture overview.

Creating a new extension

Now we will study the example “jacextension” to learn the basics of extension development in eZ Publish. We will walk through the steps of creating an extension and will look at the basic PHP classes in the eZ Publish Framework.

The tutorial will cover the following concepts:

  • Access to the database (eZ Framework – class eZPersistentObject)
  • Access to .ini configuration files (eZ Framework – class eZINI)
  • Access to GET and POST session variables (eZ Framework – class eZHTTPTool)
  • Creation of custom debug messages / log files (eZ Framework – class eZDebug)
  • Use of the privilege system for new views of a module
  • Extending the template system for your own template fetch functions or operators

Requirements

To work through the tutorial, eZ Publish must be properly installed (download the latest version here). To do this, create a default site using the eZ Publish Setup Wizard, specifying “URL” in the siteaccess configuration and a MySQL database called “ezp_plain” (character set utf-8).

This creates two siteaccesses: plain_site and plain_site_admin, accessed through the following URLs:
http://localhost/ez/index.php/plain_site (User view)
http://localhost/ez/index.php/plain_site_admin (Administrator view)
(localhost/ez/ is the root path of the eZ Publish directory.)

Setting up the extension

Now we will create and activate a new extension called “jacextension”. It will contain one module called “modul1”, with a view list that runs the PHP script "list.php". To do this we navigate to the directory extension/ beneath the main eZ Publish directory on the system command line and create a new directory called jacextension/ with the following sub-directories and PHP files:

ez/
|-- extension/
|   |-- jacextension/
|   |   |-- modules/
|   |   |   |-- modul1/
|   |   |   |   |-- list.php
|   |   |   |   |-- module.php
|   |   |-- settings/
|   |   |   |-- module.ini.append.php

In the configuration file module.ini.append.php we tell eZ Publish to search for modules in "jacextension". This will make eZ Publish try to load all modules (such as modul1), which are in the directory extension/jacextension/modules/ .

Hint: Be careful not to leave any blank spaces at the end of lines in INI entries, as the variables might not be parsed correctly.

<?php/* #?ini charset="utf-8"?
# tell ez publish to search after modules in the extension jacextension
[ModuleSettings]
ExtensionRepositories[]=jacextension
# For eZ Publish 4.1 and up you'll need to specify your module name as well
ModuleList[]=modul1
*/
?>

Listing 1. Module configuration file: extension/jacextension/settings/module.ini.append.php