PAS developer documentation

Introduction

This document is part of a new, step by step, developer documentation for PAS Core, that includes examples.

We will teach you how to program great web applications using our framework. It does not describe the GUI tools, like WebIDE or PageBuilder. It’s pure code for pure coders. The GUI tools will simplify, automate and help you get things done faster; but if you want to understand everything on the backend, this is the documentation you must read.

If you are already experienced in programming with PAS you can use the Developer Reference Documentation: PDF Download

We will proceed step by step using examples to explain the 5 main concept and design pattern in PAS. The Reports (forms and display), Registry, Queries, Events (events, eventactions, eventcontroler) and Packages.

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

What is PAS

PAS (Application Server for PHP) is a collection of classes to manipulates database data and enable the MVC (Model, View Controller) pattern.

At less than 20 files it is very small–we call it PAS Core. PAS Core only contains the minimum base classes required by every other feature of the framework; including external/add on packages. In this documentation we will only discuss PAS Core.

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

PAS Core is the foundation Open Source Fusion.

Base concept

The bases and philosophy of PAS 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 PAS on http://www.opensourcefusion.org/ or http://www.sqlfusion.org/

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

   tar -zxvf pas_full-3.7.tar.gz

Development version

The CVS repository is currently at SourceForge

A daily snapshot is available at: http://dev.sqlfusion.com/pas_full_cvs.tar.gz

To get the lastest CVS version of PAS Core and PAS SiteManager you can do at the root of your web directory: if using xampp:

   cd /opt/lampp/htdocs/

Then

   cvs -z3 -d:pserver:anonymous@cvs.sourceforge.net:/cvsroot/sqlfpas co -P pas
   cvs -z3 -d:pserver:anonymous@cvs.sourceforge.net:/cvsroot/passitemanager co -P passitemanager
   cvs -z3 -d:pserver:anonymous@cvs.sourceforge.net:/cvsroot/passitemanager co -P studio

Setup

Then with your favorite text editor Edit the passitemanager/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 passitemanager/projects
  chmod a+rw passitemanager/package
  chmod a+rw passitemanager/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 use 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

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

A 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 PAS Core object in your pages the only requirement is to include the config.php file.

Reports

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

There are two context, 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 PAS 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 uses html templates to display the forms and database data. By default PAS 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 arrive to a list of packages. Find 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 template in your training project.

Now lets create 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 PAS. Its the primary key naming convention. Every table are required to have a unique primary key with auto increment. The naming convention is the following: id<tablename>

Report Form

Now that we have created the table, lets create a form to add a few records in it.

<?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 use the one created in the config.php file: $conx.

The setDefault method use a default report template to build the HTML form. The report templates are in the report folder, in the config.php file their is a constant PAS_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 build using the table field names. Now we would like to hide the primary key, change a few fields size, set default value or set some field 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 a database fields should be display 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 is a detail explanation 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 permanant 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 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 of a table, this will becaume the default registry for that table.

We can now remove all the custom registry creation.

    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 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 pas/templates/ a registrytemplate.reg.xml file its a sample registry file that contain 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 format “VHS” or “DVD”, so lets change the current field type to a drop down select box. Let take from pas/templates/registrytemplate.reg.xml the listboxfieldsmall registry field sample and past it in our registry/movie.reg.xml files 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 method to customize this.

You can also see in the default rdata the strange [gerfields;type;] the [] are used to replace a variable or execute a small function. In this case its 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 example and you can find all of them in the Developper 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 tel 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 details the Event object a little bit later, for now lets see how we can display the data we have submited with our form.

Report Display

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

The class is called ReportTable, add bellow 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 use 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 PAS_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 customize 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 the [report_movie_search] the [] define a variable in all the PAS templates, they will be replaced by the actual value when the prepareQuery() is runned. The variables in [] will be first replaced by session variable and then globals variable. If you want to pass variables from GET or POST you will need to add the params manualy or set them globals. You can pass parameters to prepareQuery() its an Array with param_name as key and param_value as value. In our case it would end up be:

    $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 tel the ReportTable object which query to use we call the method setSavedQuery() with the savedquery object as a parameter.

Now one of the great thing with sqlSavedQuery, you can save them in an XML file. It is like for the Registry object add 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 openning 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 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 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 example 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 accept 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 seen previously report template with different feature but to add or modify a feature you needed to create a new report template. With the interactive report template you can select the feature 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 comment its line.

Like 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 system. To serialize a Report Table object or a Report Form object make it 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 files. So it makes sense that you can also do it with report form and report table objects.

The serialized Report Form are stored in the forms folder and Report Table 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>

You can see HTML and PHP code, this row tag contain 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, like 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 templates 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 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 the 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 pass 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 PAS contain the business logic of your application.

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

Events are display 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");
 
   $e_set_var->getLink("click here NOW!!");
 
?>

This display a link “click here NEW!!” 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 technicaly executed within the EventControler object so you can access any of the event controler properties and methods.

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 controler as the page to redirect after the execution using the setDisplayNext method. When you create an event with multiple events action at least one of them needs to have a display object set as a display next.

 
pas/new_developer_documentation.txt · Last modified: 2006/11/06 09:30 by 134.139.4.66
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki