Hello World

This example will walk you through the steps of developing a simple “Hello World” extension on Vtiger 7 Framework.

Pre-requisites

  • Vtiger 7 installed on your server (assuming it would be used for development).

  • PHP CLI is setup to be invoked from the command prompt or terminal.

  • Gone through module development docs: Develop Extensions For Vtiger

Terminology

  • <vtigercrm> - root-directory / document root where Vtiger 7 is installed.

  • http://<vtigercrm> - web entry access.

Note

You can download “HelloWorld-v1.zip” from here.

Step 1: Create files

Switch to your working directory (say.. Desktop) and create the following files.

manifest.xml
modules/HelloWorld/HelloWorld.php
modules/HelloWorld/views/List.php
languages/en_us/HelloWorld.php
layouts/v7/modules/HelloWorld/List.tpl

Step 2: manifest.xml

Edit manifest.xml and fill in basic information required for getting the extension installed in Vtiger.

<?xml version="1.0"?>
<module>
        <type>extension</type>
        <name>HelloWorld</name>
        <label>Hello World</label>
        <parent>Tools</parent>
        <version>1.0</version>
        <dependencies>
                <vtiger_version>7.0.0</vtiger_version>
                <vtiger_max_version>7.*</vtiger_max_version>
        </dependencies>
</module>

Step 3: Module Class

Update the module class file (modules/HelloWorld/HelloWorld.php).

<?php
class HelloWorld {}

Note

It is recommended to have this file - although its blank will be useful later.

Step 4: View Class

Edit modules/HelloWorld/views/List.php

<?php

class HelloWorld_List_View extends Vtiger_Index_View {

        public function process(Vtiger_Request $request) {
                $viewer = $this->getViewer($request);
                $viewer->view('List.tpl', $request->getModule());
        }

}

Note

Default entry for the module from the menu is set to List View. We can customize this for every module.

Step 5: View template

Edit layouts/v7/modules/HelloWorld/List.tpl

<h1>{'Hello World'|vtranslate:$MODULE}</h1>
<h4>{'LBL_WELCOME'|vtranslate:$MODULE}</h4>

Step 6: Default i18n

Edit languages/en_us/HelloWorld.php

<?php

$languageStrings = array(
        'Hello World' => 'Hello World!',
        'LBL_WELCOME' => 'A very warm welcome to you'
);

Note

Add all the string constants used by the module - required for i18n support.

Step 7: Package files

zip -r HelloWorld-v1.zip manifest.xml modules/HelloWorld/HelloWorld.php modules/HelloWorld/views/List.php languages/en_us/HelloWorld.php layouts/v7/modules/HelloWorld/List.tpl

Refer to Package Structure

Step 8: Install in Vtiger

You can import through Module Manager UI.

Note

Importing through CLI script is given below.

cd <vtigercrm>
php -f ImportHelloWorld.php

ImportHelloWorld.php should use vtlib API to import the package.

<?php

require_once 'vtlib/Vtiger/Module.php';
require_once 'vtlib/Vtiger/Package.php';

$Vtiger_Utils_Log = true;

$package = new Vtiger_Package();
$package->import('/path/to/HelloWorld-v1.zip'); // Can be any-where on your server.

The module is now installed and ready, you can find it under All > Tools section.