- mercromina responded to »error when i try to upgrade to the last version of dizkus module (3.1)« 08:01 PM
- craigh responded to »TagIt 3.0 for Zikula« 03:58 PM
- localrags responded to »Remove contents of nuke_sc_anticracker from Database« 11:30 AM
- jmvaughn responded to »Shoutit for zikula 1.3?« 09:31 AM
- mdee responded to »Different page content under one template (tpl file) based on URL« 07:17 AM
- espaan responded to »Categories disappear when editing ...« 08. Feb
- eledril responded to »How decrease zikula cpu usage« 08. Feb
Zikula Blog
- Anatomy of Open Source Projects on Mar 07
- Continuous Review on Mar 01
- Not Invented Here on Feb 24
- How to Contribute Your Code at Github on Jan 13
- 10 Steps to Coding-Nirvana: Tips for Successful Module Writing on Nov 12
- Submitting Bug Report Tickets That Get Results on Aug 17
- Cozi Tricks #1: Syntax Highlighting on Aug 07
Login
Wiki » ModuleProgrammingPart2
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.
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;
}
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;
}
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;
}
// 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;
}
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;
}
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;
}
// 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
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 ]
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($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.
pnModGetVar($module, $name)
Back to our 'hello world' module lets add a function greetings to pnuser.php
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.
Next step: Module Programming Part 3
DeveloperDocs
CategoryDeveloperDocs
pnModDelVar('helloworld');
..
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;
}
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;
}
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;
}
// function to uninstall module
function helloworld_remove()
{
pnModDelVar('helloworld', 'myname');
pnModDelVar('helloworld', 'myage');
return true;
}
Next step: Module Programming Part 3
DeveloperDocs
CategoryDeveloperDocs
