logo-radria.gif
   
Blog Download Documentation Forum Tasks Home
Blog Download Documentation Forum Tasks Home
barside-right.gif
barside-left.gif
logo-sql.gif





PAS developer documentation

Introduction

This document is developer documentation for Radria Core.

This is for Radria Core developers - it doesn't describe how to use any GUI tools. It's pure code.

To support this documentation we suggest the Radria Core Developer Documentation

We will proceed step-by-step using examples to explain the main concepts and design patterns in Radria.

In this documentation, we will build a simple video database for our examples.

What is Radria Core

RadriaCore is a small framework, just the minimum to apply good design patterns and keep things simple.

RadriaCore is itself less than 20 files.

In this by-example documentation we will only discuss Radria Core.

The base classes enable the manipulation of database data very easily.

Base concept

The bases and philosophy of Radria are in: - Simplicity - Development Speed - Code reuse - Never one way to do things - Compatible with GUI tools

Getting started

Enough with the theory – lets get started.

Requirements

You will need a working web server with PHP and MySQL (or sqlite or postgreSQL) Personally I use XAMPP it works on Linux, Windows and MaxOSX.

You can also get a web hosting account, most of them support PHP and MySQL.

Download

Stable version

You can download a stable version of Radria on http://radria.sqlfusion.com/ or http://www.sourceforge.net/projects/radria/

Unzip one of the compressed file you have downloaded into the root directory of your web server.

   tar -zxvf radria-x.xx.tar.gz

Development version

The SVN repository is currently at SourceForge

To get the lastest SVN version of Radrie Core you can checkout at the root of your web directory: if using xampp:

   cd /opt/lampp/htdocs/

Then

 svn co https://radria.svn.sourceforge.net/svnroot/radria/RadriaCore RadriaCore                                 
 svn co https://radria.svn.sourceforge.net/svnroot/radria/SiteManager SiteManager
 svn co https://radria.svn.sourceforge.net/svnroot/radria/webide webide
The SVN version is only for Radria Core developers and should not be used if your are new to Radria

Setup

Then with your favorite text editor Edit the radria/sitemanager/config.php file and around line 170 setup your database connection:

    $mydbconx = new sqlConnect("root", "xxxxxx");
  //  $mydbconx = new sqlConnect();
 //   $mydbconx->setDatabase("passitemanager");
    $mydbconx->setUseDatabase(false) ;
    $mydbconx->setBackupSync(false) ;
    $mydbconx->setBaseDirectory($cfg_local_pasdir);
    $mydbconx->setProjectDirectory("./");
    $mydbconx->start();

We suggest to set it to a high priviledge user that can create other database and users. If you are using XAMPP on your local computer with a good firewall you can probably use your root user. Then make sure the following folders are writable by the web server

  chmod a+rw radria/sitemanager/projects
  chmod a+rw radria/sitemanager/package
  chmod a+rw radria/sitemanager/tmp

First project

Then point to the passitemanager at: passitemanager. If you are using xampp it will be http://localhost/studio/

Click on the to create the training project.

Then fill in the new project form with the database information:

This will create a new database and a new user for that database. It will also create a folder training/ on the root of your OSF tools install.

Press submit then click on the link with the name of your project to open it.

Now you are up and running with a training project to test the examples in this documentation.

Create your first page

Time to open your favorite text editor and create a new page called reportdisplay.php in your training/ project folder.

Sample content for that page would be:

<?php
    /** 
     *  reportdisplay.php page
     *  This page is for training purposes, to demonstrate
     *  how to use a report object.
     */
 
    include("config.php");
    $pageTitle = "Report Display Training";
    include("includes/header.inc.php");
 
    echo "Hello World";
 
    include("includes/footer.inc.php");
?>

This is just an example; to use Radria Core object in your pages the only requirement is to include the config.php file.

Reports

In Radria terminology Reports are simply HTML/XML templates merged with database data. Reports are NOT printable reports like in MS Access.

There are two contexts, the Display and the Form context. The Display context will display the data from the database and the Form context will generate HTML forms from the database.

With the Report class in 3 lines you can create a form to add data in a database table, or display the full content of a table with add/edit/delete manipulation.

In the Radria Core logic Reports and HTML/PHP pages should not contain business logic. All the HTML and PHP code in a report is for data presentation.

Reports use html templates to display the forms and database data. By default Radria Core comes with no templates. For the purpose of the documentation we will install a default set of report templates.

In your Site Manager click on the packages icon. You will see a list of packages. Find the one called Report Template in the Database tools. Then click on the Install button on the far right. This will install a collection of report templates in your training project.

This script creates the first table:

CREATE TABLE `movie` (
  `idmovie` int(10) NOT NULL AUTO_INCREMENT,
  `name` varchar(60) NOT NULL,
  `type` varchar(60) NOT NULL,
  `format` varchar(10) NOT NULL,
  `director` varchar(70) NOT NULL,
  `release` date NOT NULL,
  `duration` time NOT NULL,
  PRIMARY KEY  (`idmovie`)
)

You have one BIG requirement in your database structure when working with Radria. It's the primary key naming convention. Every table is required to have a unique primary key with auto increments. The naming convention is the following: id<tablename>

Report Form

Now that we have created the table, lets create a form and add a few records to it. In the reportdisplay.php script add:

<?php
 
   echo $_GET['message'];
 
   $f_movie = new ReportForm($conx);
   $f_movie->setDefault("movie");
   $f_movie->setForm();
   $f_movie->execute();
 
?>

The Report object needs a sqlconnect object, we'll use the one created in the config.php file: $conx.

The setDefault method uses a default report template to build the HTML form. The report templates are in the report folder. In the config.php file there is a constant RADRIA_DEFAULT_FORM_TEMPLATE that is set with the default report form template: default_form.

setForm will set the event with all the eventactions required to process the form data.

You can see that the form is built using the table field names. Next let's hide the primary key, change a few field sizes, set default values or set some fields as required.

Custom Form Registry

To customize the form presentation we will modify the default Registry object used on this form. The Registry is an object that describe how database fields should be displayed in the Form or Display context.

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

We create a new Registry object ry_movie and load it with the default fields from the movie table and then customize some of those fields to match our needs. Once built the Registry object is set to the form with the setRegistry method. To modify the form presentation we changed the rdata properties of the fields in the registry. There are detailed explanations of each field type and rdata properties in the Developer Reference documentation.

It would be nice if the formating we have just set could be permanent for each Report Form or Report display in our entire application.

Persistance form Registry

It is possible to save the Registry 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.

Its a two step process - first add the registryToXML after all the fields and rdata settings:

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

Then just run the PHP script and look into the training/registry/ folder. there you will find a file called movie.reg.xml. If you open the file you will 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 as a table this becomes the default registry for that table.

We can now remove all the custom registry information.

    echo $_GET['message'];
 
    $f_movie = new ReportForm($conx);
    $f_movie->setRegistry("movie");
    $f_movie->setDefault("movie");
    $f_movie->setForm();
    $f_movie->execute();

Now we can just call back the Registry we have saved by calling the setRegistry method with the name of the registry as a string. If this case it is not required as we have saved the registry with the name of the table so it will be the default registry loaded when the setDefault method is called.

Now that the registry is stored in the training/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.

Registry files

We are now going to see how to customize a form presentation (report form) by changing the registry xml file directly.

For the format field we support 2 formats, “VHS” and “DVD”, so lets change the current field type to a drop down select box. Let's copy from RadriaCore/templates/registrytemplate.reg.xml the listboxfieldsmall registry field sample and paste it in our registry/movie.reg.xml file to replace the format registry entry.

  <rfield name="format">
    <rdata type="default">[getfields;format;]</rdata>
    <rdata type="label">Format</rdata>
    <rdata type="fieldtype">strFBFieldTypeListBoxSmall</rdata>
    <rdata type="listvalues">DVD:VHS</rdata>
    <rdata type="listlabels">DVD:VHS</rdata>
    <rdata type="emptydefault">no</rdata>
  </rfield>

The listvalues rdata are the values that will be inserted in the table and listlabels the entry display in the form. The emptydefault will not allow the field to be empty.

Error Message

When we have customized the Registry we have set the name and type fields to be required. You can see in the registry file registry/movie.reg.xml that both have a rdata called require set to 1 (true).

  <rfield name="name">
    <rdata type="fieldtype">strFBFieldTypeChar</rdata>
    <rdata type="default">[getfields;name;]</rdata>
    <rdata type="label">Name or Title</rdata>
    <rdata type="required">1</rdata>
  </rfield>
  <rfield name="type">
    <rdata type="fieldtype">strFBFieldTypeChar</rdata>
    <rdata type="default">[getfields;type;]</rdata>
    <rdata type="label">Type or Genre</rdata>
    <rdata type="textline">10:60</rdata>
    <rdata type="required">1</rdata>
  </rfield>

If you try to submit the form with either field empty it will send to you a message page with an error message. Lets go over the different methods to customize this.

You can also see in the default rdata the strange [getfields;type;] the [] are used to replace a variable or execute a small function. In this case it's a function called getfields that will grab in the $_GET['fields'] array the field name value pass in parameter. We will use it to repopulate the form. The functions in [] can be used in default value of the registry but also in the queries and reports, we will see more examples and you can find all of them in the Developer reference documentation.

    echo htmlentities(stripslashes($_GET['message']));
 
    $f_movie = new ReportForm($conx);
    $f_movie->setRegistry("movie");
    $f_movie->setDefault("movie");
    $f_movie->event->addParam("errorpage", $_SERVER['PHP_SELF']);
    $f_movie->event->addEventAction("mydb.addParamToDisplayNext");
    $f_movie->setForm();
    $f_movie->execute();

We change the errorpage parameter in the default Event to tell him which page to go to when there is an error. We use the $_SERVER PHP_SELF to call the current page we are on. Then we added an EventAction to the default Event so all the fields value are sent back with the message to repopulate the form. We will detail the Event object a little bit later, for now lets see how we can display the data we have submitted with our form.

Report Display

The Report Display works like the Report Form object on a different context.

The class is called ReportTable, add below the form code the following:

    $r_movie = new ReportTable($conx);
    $r_movie->setQuery("movie");
    $r_movie->setDefault();
    $r_movie->execute();

This will display the full content of the table with Add, Edit and Delete link for data manipulation.

Report templates

The setDefaultTemplate method uses a default report template to build the HTML table. The report templates are in the report folder, in the config.php file there is a constant RADRIA_DEFAULT_REPORT_TEMPLATE that is set with the default report form template: default_report.

There are different type of report template, lets try 3 others:

    $r_movie = new ReportTable($conx);
    $r_movie->setQuery("movie");
    $r_movie->setDefaultTemplate("default_report_disp");
    $r_movie->execute();

Or

    $r_movie->setDefaultTemplate("default_report_one_row");

or

$r_movie->setDefaultTemplate("search_report_disp");

This report template will display a search box but it will not work properly until we have customized the default SQL Query to execute the search.

Custom Queries

The search box will set in the session a variable called report_movie_search the standard is repot_<tablename>_search. Now we need to build a custom query that will use this search criteria to select rows.

For that we will use the sqlSavedQuery object.

Sql Saved Query

 
    $sq_movie_search = new sqlSavedQuery($conx);
    $sq_movie_search->setQuery("SELECT * FROM `movie` 
            WHERE `name` LIKE '%[report_movie_search]%' 
               OR `type` LIKE  '%[report_movie_search]%'
               OR `format` LIKE  '%[report_movie_search]%'
               OR `director` LIKE  '%[report_movie_search]%'
               OR `release` LIKE  '%[report_movie_search]%'");
    $sq_movie_search->prepareQuery();
 
    $r_movie = new ReportTable($conx);
    $r_movie->setSavedQuery($sq_movie_search);
    $r_movie->setQuery();
    $r_movie->setDefaultTemplate("search_report_disp");
    $r_movie->execute();

We create a new sqlSavedQuery object with the default connection $conx then we set the SQL statement template of the query. Notice in the [report_movie_search] the [] defines a variable in all the Radria templates, they will be replaced by the actual value when the prepareQuery() is run. The variables in [] will first be replaced by a session variable and then by a globals variable. If you want to pass variables from GET or POST you will need to add the params manually or set them globally. You can pass parameters to prepareQuery() it's an Array with param_name as key and param_value as value. In our case it would end up as:

    $sq_movie_search = new sqlSavedQuery($conx);
    $sq_movie_search->setQuery("SELECT * FROM `movie` 
            WHERE `name` LIKE '%[search]%' 
               OR `type` LIKE  '%[search]%'
               OR `format` LIKE  '%[search]%'
               OR `director` LIKE  '%[search]%'
               OR `release` LIKE  '%[search]%'");
    $a_query_params = Array ("search" => $_SESSION['report_movie_search']);
    $sq_movie_search->prepareQuery($a_query_params);

To tell the ReportTable object which query to use we call the method setSavedQuery() with the savedquery object as a parameter.

One of the great things with sqlSavedQuery is you can save them in an XML file. It's like adding the Registry object to your code

    $sq_movie_search = new sqlSavedQuery($conx);
    $sq_movie_search->setQuery("SELECT * FROM `movie` 
            WHERE `name` LIKE '%[report_movie_search]%' 
               OR `type` LIKE  '%[report_movie_search]%'
               OR `format` LIKE  '%[report_movie_search]%'
               OR `director` LIKE  '%[report_movie_search]%'
               OR `release` LIKE  '%[report_movie_search]%'");
    $sq_movie_search->prepareQuery();
    $sq_movie_search->serializeToXML("movie_search", "movie");

After your prepareQuery() call. The first parameter is the name of your query and the second parameter is the name of the main table used in your query.

Run the script by opening the page. You should then have in your savedquery folder a file called movie_search.sq.xml.

<?xml version="1.0"?>
  <savedquery>
    <qname><![CDATA[movie_search]]></qname>
    <tablenames><![CDATA[movie]]></tablenames>
    <qpos><![CDATA[0]]></qpos>
    <qorder><![CDATA[]]></qorder>
    <query><![CDATA[SELECT * FROM `movie` 
            WHERE `name` LIKE '%[report_movie_search]%' 
               OR `type` LIKE  '%[report_movie_search]%'
               OR `format` LIKE  '%[report_movie_search]%'
               OR `director` LIKE  '%[report_movie_search]%'
               OR `release` LIKE  '%[report_movie_search]%']]></query>
    <idsavedquery><![CDATA[1]]></idsavedquery>
  </savedquery>

You can now reuse that query in all of your reports when you want to implement a search. We can remove all the sqlSavedQuery code now and use the method setSavedQuery with the name of the SavedQuery to load the query in the Report.

    $r_movie = new ReportTable($conx);
    $r_movie->setSavedQuery("movie_search");
    $r_movie->setQuery();
    $r_movie->setDefaultTemplate("search_report_disp");
    $r_movie->execute();

That is all you need now, 5 lines of code to display the table content with a search. If you want to add the data manipulation links (Add, Edit, Delete) change the report template from search_report_disp to search_report.

One time query

In a different scenario if we are sure we will never reuse that query and know that query is only related to data presentation, we can use the basic sqlQuery object to execute the query.

    $q_search = new sqlQuery($conx);
    $q_search->query("SELECT * FROM `movie` 
            WHERE `name` LIKE '%".$_SESSION['report_movie_search']."%' 
               OR `type` LIKE  '%".$_SESSION['report_movie_search']."%'
               OR `format` LIKE   '%".$_SESSION['report_movie_search']."%'
               OR `director` LIKE '%".$_SESSION['report_movie_search']."%'
               OR `release` LIKE  '%".$_SESSION['report_movie_search']."%'");
 
    $r_movie = new ReportTable($conx);
    $r_movie->setSavedQuery($q_search);
    $r_movie->setQuery();
    $r_movie->setDefaultTemplate("search_report_disp");
    $r_movie->execute();

We create a standard sqlQuery object and pass it to the report with the setSavedQuery() method.

Interactive Report Template

We have seen above a few examples of report templates to display, search or manipulate data from a table or query.

Now lets talk about a special type of report template : The Interactive report template. Its a report template that accepts parameters to activate or deactivate features.

<?php
 $r_interactive = new ReportTable($GLOBALS['conx']);
 
  // Display an add record link
  $r_interactive->setValue("display_add_link", "Yes");
  // Display an update record link
  $r_interactive->setValue("display_update_link", "Yes");
  // Display a delete record link
  $r_interactive->setValue("display_delete_link", "Yes");
  // Display a detail page link
  $r_interactive->setValue("display_detail_link", "Yes");
  // Name of the Detail page
  $r_interactive->setValue("detailpage", $idbr_detail_page);
  // Display a search box 
  // require custom query with search string format: report_tablename_search
  // $r_interactive->setValue("display_search", "Yes"); 
 
  // Additional fields value to be saved in the $eDetail_tablename object
  // $r_interactive->setValue("detail_field1_to_save", "");
  // $r_interactive->setValue("detail_field2_to_save", "");
  // $r_interactive->setValue("detail_field3_to_save", ""); 
  // $r_interactive->setValue("detail_field4_to_save", ""); 
 
  // Set custom the registry
  // $r_interactive->setRegistry("registry_name");
 
  // Separate custom registry for the form (Add / Edit)
  // $r_interactive->setValue("registryname", "name_of_form_registry");
 
 
  // Name of the primary key variable for uniq add / edit
  // $r_interactive->setPrimaryKeyVar("idtable_name");
 
  // Set a saved query
  // $r_interactive->setSavedQuery("saved_sql_query_name");
 
  // execute any set queries or make one up on a default table.
  $r_interactive->setQuery("movie");
 
  // Load the interactive report template: 
  // interactive_report, interactive_report_one_row, interactive_report_one_row_2cols
  $r_interactive->setDefault("interactive_report");
 
  // Set the maximum number of rows to display
  //$r_interactive->setMaxRows(50);
 
  $r_interactive->execute();
 
?>

We have previously seen report templates with different features but to add or modify a feature you needed to create a new report template. With the interactive report template you can select the features you want and keep the look and feel into one single template.

From the example above, to activate a feature un-comment the line and to deactivate just its comment line.

As with the report template you can find the source of the interactive reports templates in the report folder.

Custom Report Registry

Like with the Report Form you can use the Registry to customize the layout of your report display.

    $ry_movie = new Registry($conx, "movie");
    $ry_movie->fields["idmovie"]->setRData("hidden", "1");
    $ry_movie->fields["name"]->setRData("label", "Name");
    $ry_movie->fields["type"]->setRData("label", "Type");
    $ry_movie->fields["type"]->setRData("dispalign", "right");;
    $ry_movie->fields["format"]->setRData("hidden" , "1");   
 
    $r_movie = new ReportTable($conx);
    $r_movie->setRegistry($ry_movie);
    $r_movie->setQuery("movie");
    $r_movie->setDefaultTemplate("default_report_disp");
    $r_movie->execute();

We load the default movie.reg.xml registry and then customize it.

Serialize a Report or Form

Exceptions are the nightmares of templating or autogenerated systems. To serialize a Report Table object or a Report Form object its very simple to add a little HTML or PHP custom code in the output HTML/PHP.

We have previously seen that we could save a Registry or a sqlSavedQuery object in an XML file. So it makes sense that you can also do it with report form and report table objects.

The serialized Report Forms are stored in the forms folder and Report Tables are in the report folder.

When you serialize a report it becomes an XML file with HTML template for the Header, Row and Footer.

Lets take our last example and serialize it:

    $r_movie = new ReportTable($conx);
    $r_movie->setSavedQuery("movie_search");
    $r_movie->setRegistry("movie");
    $r_movie->setQuery();
    $r_movie->setDefaultTemplate("search_report_disp");
    $r_movie->serializeToXML("training.Search.Movies");

Run the PHP script, nothing will appear on the screen but in the report folder the training.Search.Movies.report.xml xml file is created. Now we can create an instance of the report object just with the report file.

   $r_movie = new ReportTable($conx, "training.Search.Movies");
   $r_movie->setQuery();
   $r_movie->execute();

The file in report/training.Search.Movies.report.xml looks for the Row tag:

    <row><![CDATA[
<TR class="<?php  if ($trclass=="tabletr1") { $trclass="tabletr2"; } else { $trclass="tabletr1";} echo $trclass;?>">
<?php 
       if (strlen("")>0) { 
       $e_detail->addParam("idmovie", "[noreg:idmovie:]"); ?>
  <TD class="tabletdsidelink"><a href="<?php echo $e_detail->getUrl();?>" class="linkupdate">Details</a></td>
     <?php } ?>
 
  <TD class="tabletdformfield" align="left">[name]</td>
  <TD class="tabletdformfield" align="right">[type]</td>
  <TD class="tabletdformfield" align="left">[director]</td>
  <TD class="tabletdformfield" align="left">[release]</td>
  <TD class="tabletdformfield" align="left">[duration]</td>
</TR>
    ]]></row>

As you can see in the HTML and PHP code, this row tag contains the HTML/PHP code that will be executed for each row of your query result. The data fields are in [] - you can use the internal functions, as in this case the noreg. By default when the report is execute the field names in [] will be processed by the Registry. If you want to only get the value from the database table without any registry processing you need to add [noreg:field_name:].

You can customize the PHP or HTML code. From here you can customize the report to your needs.

For example we can see that the report template has generated some silly PHP code:

<?php 
       if (strlen("")>0) { 
       $e_detail->addParam("idmovie", "[noreg:idmovie:]"); ?>
  <TD class="tabletdsidelink"><a href="<?php echo $e_detail->getUrl();?>" class="linkupdate">Details</a></td>
     <?php } ?>

You can see that the condition in our case will never be true. Lets just remove it to clean up our Report.

    <row><![CDATA[
<TR class="<?php  if ($trclass=="tabletr1") { $trclass="tabletr2"; } else { $trclass="tabletr1";} echo $trclass;?>">   
  <TD class="tabletdformfield" align="left">[name]</td>
  <TD class="tabletdformfield" align="right">[type]</td>
  <TD class="tabletdformfield" align="left">[director]</td>
  <TD class="tabletdformfield" align="left">[release]</td>
  <TD class="tabletdformfield" align="left">[duration]</td>
</TR>
    ]]></row>

Now lets make the customization we want. For example lets display the director's names in Bold and align the release to the right.

<TR class="<?php  if ($trclass=="tabletr1") { $trclass="tabletr2"; } else { $trclass="tabletr1";} echo $trclass;?>">   
  <TD class="tabletdformfield" align="left">[name]</td>
  <TD class="tabletdformfield" align="right">[type]</td>
  <TD class="tabletdformfield" align="left"><b>[director]</b></td>
  <TD class="tabletdformfield" align="right">[release]</td>
  <TD class="tabletdformfield" align="left">[duration]</td>
</TR>

You can do more complex customization like a link to Wikipedia:

    <TR class="<?php  if ($trclass=="tabletr1") { $trclass="tabletr2"; } else { $trclass="tabletr1";} echo $trclass;?>">   
        <TD class="tabletdformfield" align="left">
            <a href="http://en.wikipedia.org/wiki/Special:Search?search=<?php echo urlencode("[noreg:name:]"); ?>&fulltext=fulltext">[name]</a>
        </td>
        <TD class="tabletdformfield" align="right">[type]</td>
        <TD class="tabletdformfield" align="left"><b>[director]</b></td>
        <TD class="tabletdformfield" align="right">[release]</td>
        <TD class="tabletdformfield" align="left">[duration]</td>
    </TR>

In this last example we have taken the [name] field value with not registry and passed it to a URL string that will trigger a search on Wikipedia.

Events

An Event object is a set of PHP scripts triggered by user input or action.

Events and Classes in Radria contain the business logic of your application.

The different PHP scripts associated with the Event are called EventActions and are stored in the events/ folder.

Events are displayed to the users as HTML Links or HTLM Forms in the web pages.

Lets start with a very simple event that will set a variable in the session and take the user to a different page.

Create a new page called training_events.php and insert into it the following php code:

<?php
   $e_set_var = new Event("training.setVar");
   $e_set_var->addParam("varname", "my_training_var");
   $e_set_var->addParam("varvalue", "Hello World");
   $e_set_var->addParam("goto", "training_event.php");
 
   echo $e_set_var->getLink("click here NOW!!");
 
?>

This displays a link “click here NOW!!” that will execute the event action training.setVar.

An event action is a php script stored in the /events/ folder. Lets create that event action. Create a new file called events/training.setVar.inc.php with the following content:

<?php 
   /** 
    *  EventAction training.setVar
    *   
    *  Very basic sample events for training.
    *  
    */
 
  $varname = $this->getParam("varname");
  $varvalue = $this->getParam("varvalue");
  $goto = $this->getParam("goto");
 
  if (!empty($varname) && !empty($varvalue)) {
      $_SESSION[$varname] = $varvalue;
  }
 
  $disp = new display($goto);
  $disp->addParam("message", "Variable set");
 
  $this->setDisplayNext($disp);
 
?>

They are technically executed within the EventControler object so you can access any of the event controller properties and methods. l An event action gets the variables using the getParam method.

It ends with the creation of a Display object. This Display object is passed to the Event controller as the page to redirect after the execution using the setDisplayNext method. When you create an event with multiple event actions at least one of them needs to have a display object set as a display next.

 
core/by_example_php4.txt · Last modified: 2008/04/15 12:02 by 122.166.2.23
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki