Blog Download Documentation Forum Tasks Home
Blog Download Documentation Forum Tasks Home


The registry object defines how database table fields should be displayed in a web based environment. It's used in forms and in views. The Registry Field type object will generate the HTML and Javascript code needed to present the fields in forms and views.

Registry object

NOTE: the code below works only in PHP5.

The Registry is an object that describes how database fields should be displayed in the Form or Display context.

    $conx = $GLOBALS['conx'];
    $ry_movie = new Registry($conx);
    $ry_movie->idmovie->hidden = 1;
    $ry_movie->name->label = "Name or Title";
    $ry_movie->name->required = 1;
    $ry_movie->type->label = "Type or Genre";
    $ry_movie->type->textline = "10:60";
    $ry_movie->type->required = 1;
    $ry_movie->format->label =  "Format";
    $ry_movie->format->textline = "6:10";
    $ry_movie->release->label = "Date Release in Theaters";
    $ry_movie->duration->label = "Duration";
    $ry_movie->duration->default = "01:30:00";
    $f_movie = new DataObject($conx, "movie"); 

Create a registry from scratch without loading it from a database table:

$ry_movie = new Fields();
$ry_movie->addField(new FieldTypeInt('idmovie'));
$ry_movie->idmovie->hidden = 1;
$ry_movie->addField(new FieldTypeChar('name'));
$ry_movie->name->label = 'Name or Title';
$ry_movie->name->required = 1;
$ry_movie->addField(new FieldTypeChar('type'));
$ry_movie->type->label = "Type or Genre";
$ry_movie->type->size = 10;
$ry_movie->type->maxlenght = 60;
$ry_movie->type->required = 1;

We're creating a new Registry object ry_movie and loading it with the default fields from the movie table and then customizing some of those fields to match our needs. Once built the Registry object is set to the DataObject with the setRegistry method. To modify the form presentation we changed the rdata properties of the fields in the registry. There is a detailed explanation of each field type and rdata properties later in this chapter. It would be nice if the formating we have just set could be permanent for each Form, View or Report in our entire application. For this we serialized the Registry Object.. Persistence Registry It is possible to save the Registry Object and call it back when needed. To do that you need to call the Registry method registryToXML, it will write an XML file in the registry folder of your project. It's a two step process first add the serializeToXML after all the fields and rdata settings:

    $ry_movie = new Registry($conx);
    $ry_movie->fields["idmovie"]->hidden = 1;
    $ry_movie->fields["name"]->label = "Name or Title";
    $ry_movie->fields["name"]->required = 1;
    $ry_movie->fields["type"]->label = "Type or Genre";
    $ry_movie->fields["type"]->textline = "10:60";
    $ry_movie->fields["type"]->required =  1;
    $ry_movie->fields["format"]->label = "Format";
    $ry_movie->fields["format"]->textline =  "6:10";
    $ry_movie->fields["release"]->label = "Date Release in Theaters";
    $ry_movie->fields["duration"]->label =  "Duration";
    $ry_movie->fields["duration"]->default = "01:30:00";

Then just run the PHP script, look in the registry/ folder and you will find a file called movie.reg.xml. Open the file and you find all the fields, their type and all the associated rdata, the default one and the one you have customized. When you create a Registry file with the same name of a table, this will become the default registry for that table. We can now remove all the custom registry creation.

    echo $_GET['message'];
    $f_movie = new DataObject($conx);

Now we can call back the Registry we have saved by using the setRegistry method with the name of the registry as a string. Now that the registry is stored in the registry/movie.reg.xml file you can customize it directly by editing the xml file. In RadriaCore/templates/ a registrytemplate.reg.xml file its a sample registry file that contains most of the default fields and their rdata properties.

Serialized registry file

Registry file format

The registry file has same name as the table it is attached to. For Example: a table called customers would have a registry file called registry/customers.reg.xml The registry file is an XML file that starts with the following : <?xml version=“1.0”?> <registry> and ends with : </registry> In between the two registry tags is a series of rfield tags described below. Each rfield tag contains the name of a field in the table and rdata tags that are options for that specific field and type.

Example of a registry file email.reg.xml :

<?xml version="1.0"?>
  <rfield name="active">
    <rdata type="default">1</rdata>
    <rdata type="hidden">1</rdata>
    <rdata type="label">Active</rdata>
    <rdata type="fieldtype">strFBFieldTypeCheckBox</rdata>
    <rdata type="checkbox">1</rdata>
  <rfield name="idmailinglist">
    <rdata type="default">[idlist]</rdata>
    <rdata type="hidden">1</rdata>
    <rdata type="textline">:</rdata>
    <rdata type="fieldtype">strFBFieldTypeInt</rdata>
  <rfield name="email">
    <rdata type="default">[retryemail]</rdata>
    <rdata type="email">1</rdata>
    <rdata type="label">Email</rdata>
    <rdata type="textline">20:40</rdata>
    <rdata type="fieldtype">strFBFieldTypeEmail</rdata>
  <rfield name="idemail">
    <rdata type="hidden">1</rdata>
    <rdata type="fieldtype">strFBFieldTypeInt</rdata>
  <rfield name="dategone">
    <rdata type="label">Date Unsubscribe</rdata>
    <rdata type="datesql">m/d/Y:never:</rdata>
    <rdata type="fieldtype">strfFBFieldTypeDateSQL</rdata>
  <rfield name="datesubscribe">
    <rdata type="label">Date Subscribe</rdata>
    <rdata type="datesql">m/d/Y:today:1</rdata>
    <rdata type="fieldtype">strfFBFieldTypeDateSQL</rdata>

This registry file describes the fields for a table called email that stores emails for a mailing list.

Special Default field values

The default value for a field can be string of text, a session or a global variable. To call a session or global variable as a default value for a field use the following syntax: [global_variable_name] If you need to execute some PHP code before returning the default value you can call a function.

The syntax is the following:


When the field will be rendered in the form context the registry will call the function function_name and pass it all the parameters as an Array, the return value will be the default value for that field.

Existing default value functions

You can find the default Radria function in the file: RadriaCore/class/libReport.php

getparam : Requires 2 parameters: saved_event_name and param_name. saved_event_name is the name of the event that as been saved in the session. (see Saved Events in Event chapter) and param_name is the name of a parameter of that saved event. Usage: [getparam;saved_event_name;param_name]

getfields: requires 1 parameters, its the name of the of the fields from the fields array. Fields array comes from forms generated with the registry. This function is useful when used with mydb.addParamToDisplayNext to repopulate fields with values just previously entered by the user. For example after a failed form validation. Usage: [getfields;field_name]

getfromarray: Requires 2 parameters array_name and key_name and grab a value from an array_name using key_name. Usage: [getfromarray;array_name;key_name]

getsession: require 1 parameter and will return the value from a variable in the session. Usage: [getsession;varname;]

Create new default value functions

As an example here is the source code of getfromarray:

 function getfromarray($params) {   
    global $$params[1];
    $arrayname = $$params[1];
    $fieldname = $params[2];
    if (is_array($arrayname)) {
      return $arrayname[$fieldname];
    } else {
      return '';

Your function accepts one parameter. This parameter is an Array with the first value being the name of the function and all other values are the different parameters.

core/registry/registry_object.txt · Last modified: 2011/03/05 17:18 by admin
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki