IceHrm
Search…
Creating First Extension
Here we introduce IceHrm extensions and covers the steps needed to create a basic extension

Introduction

IceHrm extensions allow developers to extend the features offered by IceHrm without making changes to the IceHrm core. Here we will start building an extension to list some tasks for employees
    Create the directory icehrm/extensions if it doesn't exist
    Create a directory named tasks inside icehrm/extensions

Add meta.json file

1
icehrm
2
|--extnsions
3
|--tasks
4
|--meta.json
Copied!
The meta.json file for this extension should look like:
1
{
2
"label": "My Tasks",
3
"menu": ["Tasks", "fa-list"],
4
"icon": "fa-tasks",
5
"user_levels": [
6
"Admin",
7
"Manager",
8
"User"
9
],
10
"model_namespace": "\\Tasks\\Model",
11
"manager": "\\Tasks\\Extension",
12
"headless": false
13
}
Copied!
    menu: the name of the main menu and the icon for the main menu
    label: the name of the menu item that will be created by this extension
    icon: the icon for the menu that will hold the extension
    user_levels: which types of users will be able to see and use the extension (in this case Admins / Managers and Employees)
    headless: if true this extension will not have any UI visibility. It'll just function as a background module
    manager: the main class which will control the extension
    model_namespace: the namespace which will hold all the database model classes

Add Extension Manager Class

1
icehrm
2
|--extnsions
3
|--tasks
4
|--src
5
|--Tasks
6
|--Extension.php
7
|--meta.json
Copied!

Extension.php

1
<?php
2
namespace Tasks;
3
4
use Classes\IceExtension;
5
6
class Extension extends IceExtension
7
{
8
9
public function install() {
10
11
}
12
13
public function uninstall() {
14
15
}
16
17
public function setupModuleClassDefinitions()
18
{
19
20
}
21
22
public function setupRestEndPoints()
23
{
24
25
}
26
}
Copied!

Adding Extension Include File

Every extension should have an include file with the same name as the extension. In our example, it will be tasks.php
1
icehrm
2
|--extnsions
3
|--tasks
4
|--src
5
|--Tasks
6
|--Extension.php
7
|--meta.json
8
|--tasks.php
Copied!

tasks.php

1
<?php
2
3
require_once __DIR__.'/src/Tasks/Extension.php';
Copied!

Adding the View file

Every extension must have a view file if it's not running on headless mode. File should always be <extension_dir>/web/index.php
1
icehrm
2
|--extnsions
3
|--tasks
4
|--src
5
|--Tasks
6
|--Extension.php
7
|--web
8
|--index.php
9
|--meta.json
10
|--tasks.php
Copied!

web/index.php

1
<?php
2
$user = \Classes\BaseService::getInstance()->getCurrentUser();
3
echo "Welcome ".$user->username;
Copied!
Here we use a core class from Icehrm to get the currently logged in user

Load the Extension in IceHrm

Visit http://icehrm.os and you should see the My Tasks menu
Last modified 11mo ago