Last edit 2009-06-01 21:31:13 by Paustian [ Added note about reading basic module structure ]

Additions
Your module is of course an interface for the data that you are storing. If you have not already, familiarize yourself with the Basic Module Structure before proceeding. There are two classes of data that you might want to store. One I will call instance data (data that is involved with what your module does), and the other admin data, information that affects all instances of a module. For example, imagine that you have a movie rating database. The names of the movies, their year, the studio, major actors in the film, and the rating given would be instance data. The number of movies to display per page would probably be an admin variable that would control display. Zikula can store admin data for a module in it's registry. This page describes the very simple process for getting and storing admin data. We don't need to concern ourselves with any data access as we have three standardized calls which will get, set and delete values.

Deletions
Your module is of course an interface for the data that you are storing. There are two classes of data that you might want to store. One I will call instance data (data that is involved with what your module does), and the other admin data, information that affects all instances of a module. For example, imagine that you have a movie rating database. The names of the movies, their year, the studio, major actors in the film, and the rating given would be instance data. The number of movies to display per page would probably be an admin variable that would control display. Zikula can store admin data for a module in it's registry. This page describes the very simple process for getting and storing admin data. We dont need to concern ourselves with any data access as we have three standardised calls which will get, set and delete values.


_EDITED 2009-04-18 14:35:33 by Paustian [ ]

Additions

Module Variables


Your module is of course an interface for the data that you are storing. There are two classes of data that you might want to store. One I will call instance data (data that is involved with what your module does), and the other admin data, information that affects all instances of a module. For example, imagine that you have a movie rating database. The names of the movies, their year, the studio, major actors in the film, and the rating given would be instance data. The number of movies to display per page would probably be an admin variable that would control display. Zikula can store admin data for a module in it's registry. This page describes the very simple process for getting and storing admin data. We dont need to concern ourselves with any data access as we have three standardised calls which will get, set and delete values.


pnModSetVar()


pnModSetVar($module, $name, $value)

One would normally initialise module variables in the modules initialisation script pninit.php. This is done at module installation time only and registers the variables with the Zikula registry. Open up pninit.php in the helloworld folder, find the function helloworld_init and rewrite the function so it looks as shown below.

// pninit.php
function helloworld_init()
{
    if (!DBUtil::createTable('helloworld')) {
        return false;
    }
    pnModSetVar('helloworld', 'myname', 'Fred Bloggs');
    pnModSetVar('helloworld', 'myage', 32);
    //initialization successful return true
    return true;
}



pnModGetVar()


pnModGetVar($module, $name)

Back to our 'hello world' module lets add a function greetings to pnuser.php

// pnuser.php
function helloworld_user_greetings()
{
    // get the variable 'myname' which belongs to the module 'helloworld' from the registry
    $myname = pnModGetVar('helloworld', 'myname');

    // get the variable 'myage' which belongs to the module 'helloworld' from the registry
    $myage= pnModGetVar('helloworld', 'myage');

    $greeting = "Hello World.  My name is $myname and I am $myage";

    // function returns to Zikula Application Framework.
    return $greeting;
}


Do not rely on the return value to test for success of these calls! If the module variable does not exist, pnModGetVar() returns false. If your module var is likely to hold a boolean, you might get into trouble. For example, you test to see if a variable is true, pnModGetVar cannot find that variable and returns false. This is not what you expected and could lead to poor results. It is better store such data as a string, 'on' for true and 'off' for false, to avoid problems.


pnModDelVar()


pnModDelVar($module, $name)

This function would normally be used during the uninstall of a module in pninit.php It removes the variables from the registry.

// pninit.php
// function to uninstall module
function helloworld_remove()
{
    pnModDelVar('helloworld', 'myname');
    pnModDelVar('helloworld', 'myage');

    // delete all module vars in one step
    pnModDelVar('helloworld');
   
    return true;
}


Next step: Module Programming Part 3

DeveloperDocs



Deletions

Module Variables


Zikula can store variable for a module in it's registry. We dont need to concern ourselves with any data access as we have three standardised calls which will get, set and delete values.


pnModSetVar()


pnModSetVar($module, $name, $value)

One would normally initialise module variables in the modules initialisation script pninit.php. This is done at module installation time only and registers the variables with the Zikula registry.

// pninit.php
function helloworld_init()
{
    pnModSetVar('helloworld', 'myname', 'Fred Bloggs');
    pnModSetVar('helloworld', 'myage', 32);
    return true;
}



pnModGetVar()


pnModGetVar($module, $name)

Back to our 'hello world' module lets add a function greetings to pnuser.php

// pnuser.php
function helloworld_user_greetings()
{
    // get the variable 'myname' which belongs to the module 'helloworld' from the registry
    $myname = pnModGetVar('helloworld', 'myname');

    // get the variable 'myage' which belongs to the module 'helloworld' from the registry
    $myage= pnModGetVar('helloworld', 'myage');

    $greeting = "Hello World.  My name is $myname and I am $myage";

    // function returns to Zikula Application Framework.
    return $greeting;
}


Do not rely on the return value! If the module variable does not exist, pnModGetVar() returns false. If your module var is likely to hold a boolean, you might get into trouble. Better store such data as 'on' for true and 'off' for false to avoid problems.


pnModDelVar()


pnModDelVar($module, $name)

This function would normally be used during the uninstall of a module in pninit.php It removes the variables from the registry.

// pninit.php
// function to uninstall module
function helloworld_remove()
{
    pnModDelVar('helloworld', 'myname');
    pnModDelVar('helloworld', 'myage');

    // delete all module vars in one step
    pnModDelVar('helloworld');
   
    return true;
}


Next step: Module Programming Part 3

DeveloperDocs




_EDITED 2006-09-11 14:09:34 by Landseer [ ]

Additions
Do not rely on the return value! If the module variable does not exist, pnModGetVar() returns false. If your module var is likely to hold a boolean, you might get into trouble. Better store such data as 'on' for true and 'off' for false to avoid problems.
delete all module vars in one step
pnModDelVar('helloworld');
..


Oldest known version of this page was edited on 2006-06-21 20:54:24 by markwest [ fixed wiki words ]

Module Variables



Zikula can store variable for a module in it's registry. We dont need to concern ourselves with any data access as we have three standardised calls which will get, set and delete values.


pnModSetVar()


pnModSetVar($module, $name, $value)

One would normally initialise module variables in the modules initialisation script pninit.php. This is done at module installation time only and registers the variables with the Zikula registry.

// pninit.php
function helloworld_init()
{
    pnModSetVar('helloworld', 'myname', 'Fred Bloggs');
    pnModSetVar('helloworld', 'myage', 32);
    return true;
}



pnModGetVar()


pnModGetVar($module, $name)

Back to our 'hello world' module lets add a function greetings to pnuser.php

// pnuser.php
function helloworld_user_greetings()
{
    // get the variable 'myname' which belongs to the module 'helloworld' from the registry
    $myname = pnModGetVar('helloworld', 'myname');

    // get the variable 'myage' which belongs to the module 'helloworld' from the registry
    $myage= pnModGetVar('helloworld', 'myage');

    $greeting = "Hello World.  My name is $myname and I am $myage";

    // function returns to Zikula Application Framework.
    return $greeting;
}



pnModDelVar()


pnModDelVar($module, $name)

This function would normally be used during the uninstall of a module in pninit.php It removes the variables from the registry.

// pninit.php
// function to uninstall module
function helloworld_remove()
{
    pnModDelVar('helloworld', 'myname');
    pnModDelVar('helloworld', 'myage');
    return true;
}


Next step: Module Programming Part 3

DeveloperDocs

CategoryDeveloperDocs