PostNuke: A Flexible Open Source Content Management System
home | forum | international support | contact us

Documentation Wiki

Module Variables


PostNuke 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 PostNuke 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 PostNuke 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

CategoryDeveloperDocs
XML Revisions of $tag
Page history :: Last Editor [ Landseer ] :: Owner [ Chestnut ] ::
Valid XHTML :: Valid CSS :: Powered by pnWikka 1.0 (A wiki fork from WikkaWiki)
 

Main Menu

Extensions Database

Documentation

Development

Login





 


 Log in Problems?
 New User? Sign Up!

Donate to PostNuke