12.3 PHP code
Note that the database editors use phpGrid, a complex product, purchased from HongKong.
phpGrid is discussed separately. The examples here are of other use of PHP code.
PHP code is always located between tags thus: <?php .... code here.... ?>
PHP code may be:
- embedded in web page HTML code
- this will run when the web page is loaded (rendered).
- in a dedicated .php file on the server
- this will run when the file is launched from the client.
Embedded PHP code.
It is the version statement at the left of the footer bar. (on all three webpages)
The version is in wcversion.php, a very simple file as shown:
$ver = 1.001;
$version = "1.001";
At the start of the web page we have: require_once "cat/phpfiles/wcversion.php";//
The file sets PHP variables $ver and $version (All PHP variables must begin with a $ character)
Embedded PHP code is only valid for the duration of the initial rendering of the page.
So these definitions are lost once page rendering is complete.
Further down the web page HTML code, we write the text of the footer:
<span style="color:yellow">piWebCat version <?php echo $version; ?></span>
<span>....text ... </span> is a way of formatting text and labelling text
- We set attributes in <span>. which are applied to the enclosed text.
A <span> tag can have a number of attributes, one of which is style.
Style then has a wide range of attributes ... as used in .css style sheet files.
Here we simply set text color to yellow. (We are already working on blue background)
The first part of the text is: piWebCat version
The second part is embedded PHP code: <?php echo $version; ?>
The extensively used PHP echo command is run on the server at this point in building
the HTML text to send to the client.
The echo command sends text to the client in the middle of rendering the web page,
and so the value of $version is inserted in the web page..
So we see on web page footer : version 1.001 .
Embedded PHP code example 2
The database editor uses phpGrid to show the database tables in a grid presentation.
Twelve grids are built (from 12 database tables) when the page is constructed on the client.
... at any one time we hide 11 of them!
phpGrid is purchased from a Hongkong company. I have an OEM distribution license.
phpGrid allows the creation of complex database aware grids with only a few lines of PHP code.
It has in line editing on grid.
A single line of PHPcode can set one of the grid's columns to behave as a drop down list selector.
We have a list of radios in the database rigs table.
We need to present the radios in a drop down list for selection.
To do this, we can add a PHP code line to the grid initialisation .. of the form:
The list controlling string here is: FT2000:FT2000;FTdx101D:FTdx101D;....
FT2000:FT2000 is a key - data pair.
- The first FT2000 is the identifier and is written to the database table
- The second FT2000 appears in the drop list for selection
( They don't have to be the same ... but they are the same in all piWebCAT usage.)
Therefore, to generate a drop list of radios, we need a string:
FT2000:FT2000;FTdx101D:FTdx101D;IC7000:IC7000; etc for all the radios.
File wcradioselector.php generates this string from the list of radios in the database.
It places the radiolist string in variable $RadioSelect.
The editor page is catedit.php.
We place: require_once "cat/phpfiles/wcradioselector.php" at the start of catedit.php.
This runs the code in wcradioselector.php and results in $RadioSelect being available
on the server for the duration of the page build.
We add set_col_edittype(..) to the set up of each grid, using the radio list in $RadioSelect:
$bg -> set_col_edittype("rig", "select",$RadioSelect,false);
This makes the rig column, on edit present drop down radios list.