Dynamicly change contents of cell Default: You can reformat a field's data before displaying it in a HTML grid cell using powerLens. For example, if you have 2 columns, say firstname and surname you can combine them using:
{firstname} {surname}
If you want to have the surname first, with the firstname in italics:
{surname}, {firstname}
If you want the surname in uppercase you can do so by executing PHP code.
To execute PHP code, set the first character to an equals (=). This will treat all following text as PHP code.
=strtoupper({surname}) . ", " .{firstname} . ""
You can access also global variables using the $GLOBALS[] array, or call PHP functions.
Empty Fields and NBSP
Sometimes you want to check if a field is empty/null. You cannot check by using if empty({column}) because all empty columns are set to & nbsp; for display purposes. Nor can you compare if ({column} == '& nbsp;') because semi-colon ; is used to separate column settings.
NOTE: Since phpLens 2.6.5, we allow you to disable conversion of empty strings to & nbsp;. You do this by prefixing a % or =% to your powerLens. Here are two examples:
%<a href=someurl.com/?param={param}>{value}</a>
=%'<a href=someurl.com/?param='.urlencode({param}).'>'.{value}.'</a>';
Before 2.6.5, you had to use this technique: We also have defined a variable {NBSP} to represent & nbsp; . So you can check if a field is empty using if ({column} == {NBSP}).
Similarly for formatting, when you want to add additional spaces between words:
Name: {NBSP} {Name}
Lastly if you need to display an ISO entity, for example the bullet symbol (•) • you can use the {SEMICOLON} variable:
"•{SEMICOLON}";
If the field you are accessing is numeric, we automatically format the number with the thousand's separator. So if you have a column called {kg} and you want the raw unformated data, the raw data is available in the $_flds array. Note that the _flds array might be indexed by number, not by field name (depends on the database).
More Examples
| | Description | PowerLens Code | | 1 | Show column {c} as bold | {c} | | 2 | Capitalize first character of each word in column {c} using the PHP ucwords function | =ucwords({c}) | | 3 | Combine 3 columns in one: {book}, {chapter}, {verse} so it will appear as
[Genesis 2:3] | [{book} {chapter} : {verse}] | | 4 | Create a hyperlink | {linktext} |
Global Variables
The $GLOBALS[] array is accessible from a powerLens. For example, to access $PHP_SELF, use {$PHP_SELF}.
Record Numbers
This is new to phpLens 1.2. Each row is assigned a record number and this can be obtained using the special {_RECNO_} variable. Useful for switching detail grids dynamically. The currently selected row number is stored in {_HILITE_RECNO_}.
Complete List of Macro Variables
{NBSP} = ' '
{SEMICOLON} = ';'
{_RECNO_} = record number powerLens is acting on
{_HILITE_RECNO_} = currently selected record number
{_LENSID_} = the phpLens object's id
{_ODDC_} = the odd row color
{_EVENC_} = the even row color
{_SELECTC_} = the hilite color for the selected record
{_HASDETAILS_} = whether the detail grid is visible
See Also
See also colorLens.
Also see the inputTypeLens property to change the input type to checkbox, radio or submit buttons.Syntax
# modify the firstname column to show both surname and firstname
$lens->powerLens = "FIRSTNAME^{surname}, {firstname}";
# modifies firstname to show the surname in uppercase
$lens->powerLens = "FIRSTNAME^=strtoupper({surname})", ".{firstname}.""; Basic:Yes Advanced/Enterprise:Yes DynamicEdit:Yes [Version 1.0]
|