IceHrm
Here we introduce IceHrm extensions and cover the steps needed to create a basic extension.
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
Code for this extension is here: https://github.com/gamonoid/icehrm/tree/feature/custom-extentions-example/extensions/tasks
📦extensions ┣ 📂tasks ┃ ┗ 📜meta.json ┗
{ "label": "My Tasks", "menu": ["Tasks", "fa-list"], "icon": "fa-tasks", "user_levels": [ "Admin", "Manager", "User" ], "model_namespace": "\\Tasks\\Model", "manager": "\\Tasks\\Extension", "headless": false }
📦extensions ┣ 📂tasks ┃ ┣ 📂src ┃ ┃ ┗ 📂Tasks ┃ ┃ ┃ ┗ 📜Extension.php ┃ ┗ 📜meta.json ┗
<?php namespace Tasks; use Classes\IceExtension; class Extension extends IceExtension { public function install() { } public function uninstall() { } public function setupModuleClassDefinitions() { } public function setupRestEndPoints() { } }
Every extension should have an include file with the same name as the extension. In our example, it will be tasks.php
📦extensions ┣ 📂tasks ┃ ┣ 📂src ┃ ┃ ┗ 📂Tasks ┃ ┃ ┃ ┗ 📜Extension.php ┃ ┣ 📜meta.json ┃ ┗ 📜tasks.php ┗
<?php require_once __DIR__.'/src/Tasks/Extension.php';
Every extension must have a view file if it’s not running on headless mode. The file should always be <extension_dir>/web/index.php
📦extensions ┣ 📂tasks ┃ ┣ 📂src ┃ ┃ ┗ 📂Tasks ┃ ┃ ┃ ┗ 📜Extension.php ┃ ┣ 📂web ┃ ┃ ┗ 📜index.php ┃ ┣ 📜meta.json ┃ ┗ 📜tasks.php ┗
<?php $user = \Classes\BaseService::getInstance()->getCurrentUser(); echo "Welcome ".$user->username;
Here we use a core class from Icehrm to get the currently logged in user.
Visit http://icehrm.os and you should see the My Tasks menu.
Powered by BetterDocs