pclib
3.0.0
Lightweight PHP framework
|
Template engine. More...
Public Member Functions | |
__construct ($path='', $sessName='') | |
Load and parse template file. More... | |
init () | |
Initialization - must be called after load() | |
load ($path) | |
Load template file. More... | |
loadString ($s) | |
Load string $s as template. More... | |
out ($block=null) | |
Display template populated with content. More... | |
html ($block=null) | |
Return html output of the template populated with content. More... | |
enable () | |
Enable (show) or disable (hide) tag or block $name. More... | |
disable () | |
Disable (hide) tag or block $name. More... | |
setAttr ($id, $value, $value2=null) | |
Set attribute globally for template elements. More... | |
getBlock ($block) | |
Return values of block $block. More... | |
getValue ($id) | |
Return value of element $id. More... | |
loadSession () | |
Load object from session. | |
saveSession () | |
Save object to session. | |
deleteSession () | |
Remove object from session. | |
create ($tableName, $templatePath='') | |
Use default template for displaying database table content. | |
print_Element ($id, $sub, $value) | |
This function is called for each template tag when it is printed. More... | |
print_Number ($id, $sub, $value) | |
Print numeric $value. More... | |
print_String ($id, $sub, $s) | |
Print string $value. More... | |
print_Bind ($id, $sub, $value) | |
Bind $value to LABEL coming from datasource and print LABEL. More... | |
print_Link ($id, $sub, $value) | |
Create html link. More... | |
print_Env ($id, $sub, $value) | |
Print value from url (from _GET array). More... | |
print_Class ($id, $sub, $value) | |
Print all fields into template. More... | |
print_Action ($id, $sub, $value) | |
Call controller's method and include result into template. More... | |
print_Block ($block) | |
Print template block. More... | |
addTag ($line) | |
Add new element. More... | |
addType ($name, $fn) | |
Add new type of element handled by callback function $fn. More... | |
setFields ($fields) | |
Show only this $fields in template (using tag {grid.fields} or {form.fields}). More... | |
htmlTag ($name, $attr=[], $content=null) | |
Return html tag $name with attributes. More... | |
Public Member Functions inherited from BaseObject | |
loadDefaults ($className=null) | |
Load default parameters of class $className into object instance. | |
setProperties (array $defaults) | |
Set public properties of object from the array. More... | |
toArray () | |
Convert object to array. More... | |
Data Fields | |
$name | |
Name of the template. | |
$elements = array() | |
Array of elements loaded from <?elements ? > section. | |
$values = array() | |
Array of template values. | |
$db | |
var Db | |
$router | |
var Router | |
$escapeHtmlFunction | |
Function for escaping html in template values. | |
Data Fields inherited from BaseObject | |
$serviceLocator | |
var function() Return service object when requested with service(). | |
Protected Member Functions | |
getAttr ($id, $attr) | |
Return attribute of element $id. More... | |
getVariable ($id) | |
Get template variable tvar... | |
getRowNo () | |
Return row number of the current block. | |
createFromTable ($tableName, $templatePath) | |
Use default template for displaying database table content. | |
compute ($id) | |
Return computed value of element $id. | |
trPrintElement ($elem) | |
Print element in table layout. More... | |
getPopup ($id, $attr, $url) | |
Generate javascript code for popup window. More... | |
getUrl ($elem) | |
Return url for the element (button, link) with completed parameters. | |
formatDate ($dtstr, $fmt='') | |
DATABASE DATE => HUMAN DATE (in date() format) More... | |
formatStr ($s, $fmt) | |
Format string $s according format $fmt. | |
getItems ($id) | |
Load lookup table for elements such as bind, select, check or radio. More... | |
Protected Member Functions inherited from BaseObject | |
service ($service, $default=null) | |
Try acquire $service and load it into property $this->$service. More... | |
Protected Attributes | |
$sessName | |
Name of the session variable where template values are stored. More... | |
$app | |
var App Link to application object. | |
$config = null | |
Link to array of configuration parameters. | |
$document | |
Document array - It contains parsed template. | |
$parser | |
var TplParser | |
$fields = [] | |
List of id's to be printed in {grid.fields} tag. | |
$types = [] | |
Additional element type handlers. | |
Additional Inherited Members | |
Static Public Member Functions inherited from BaseObject | |
static | defaults () |
Set or retireve default parameters of the object. More... | |
Template engine.
Load template, populate it with values and display it. Template is usually html file with template tags {TAGNAME}. Features:
See Template tags implemented by class Tpl for description of implemented tags.
__construct | ( | $path = '' , |
|
$sessName = '' |
|||
) |
Load and parse template file.
string | $path | Filename of template file |
string | $sessName | When set, object is stored in session as $sessName |
addTag | ( | $line | ) |
Add new element.
string | $line | Element definition in template file syntax - e.g. "string Title noprint" |
addType | ( | $name, | |
$fn | |||
) |
Add new type of element handled by callback function $fn.
string | $name | Name of new type |
callable | $fn | function($obj, $id, $sub, $value) |
disable | ( | ) |
Disable (hide) tag or block $name.
array|list | of tag names |
enable | ( | ) |
Enable (show) or disable (hide) tag or block $name.
$tpl->enable('tag'); $tpl->enable('tag1','tag2'); $tpl->enable('tag', false);
array|list | of tag names | |
bool | $val | Enable? true|false |
|
protected |
DATABASE DATE => HUMAN DATE (in date() format)
|
protected |
Return attribute of element $id.
Perform cascading search of attribute value - if attr is not found in element it will look in element's block and template header.
string | $id | Element Id |
getBlock | ( | $block | ) |
Return values of block $block.
string | $block | Id of template block |
|
protected |
Load lookup table for elements such as bind, select, check or radio.
Element must contains exactly one of following attributes: list, query, lookup. See Common attributes of template tags. You can set array of items directly: $t->_element->items = $items;
int | $id | identificator of element |
|
protected |
Generate javascript code for popup window.
string | $attr | popup attribute of element (Example: popup "600x400+100+100") |
string | $url | url of page to open |
getValue | ( | $id | ) |
Return value of element $id.
string | $id | Element Id |
Reimplemented in Form.
html | ( | $block = null | ) |
Return html output of the template populated with content.
string | $block | If set, only html of the block $block will be returned. |
htmlTag | ( | $name, | |
$attr = [] , |
|||
$content = null |
|||
) |
Return html tag $name with attributes.
$attr: "<$name $attr>$content</$name>".
load | ( | $path | ) |
loadString | ( | $s | ) |
Load string $s as template.
Useful, if you need read template from another source than filesystem.
string | $s | string containing template source |
out | ( | $block = null | ) |
print_Action | ( | $id, | |
$sub, | |||
$value | |||
) |
Call controller's method and include result into template.
Example: action comments route "comments/list/id:{id}" will call method CommentsController::listAction($id)
string | $id | name of template tag {ID} |
string | $sub | modificator (second part) of template tag name {ID.sub} |
mixed | $value | value of element going from Tpl->values array |
print_Bind | ( | $id, | |
$sub, | |||
$value | |||
) |
Bind $value to LABEL coming from datasource and print LABEL.
Datasource can be specified using attributes list, query or lookup. See Common attributes of template tags for details.
string | $id | name of template tag {ID} |
string | $sub | modificator (second part) of template tag name {ID.sub} |
mixed | $value | value of element going from Tpl->values array |
print_Block | ( | $block | ) |
Print template block.
Block is template section marked with:
Block is treated like normal template element. It's posible hide whole block (noprint) or repeat block n-times (repeat "n"). Warning! It's sharing namespace with another elements, so his name must be unique.
string | $id | name of template tag {ID} |
string | $sub | modificator (second part) of template tag name {ID.sub} |
mixed | $value | value of element going from Tpl->values array |
print_Class | ( | $id, | |
$sub, | |||
$value | |||
) |
Print all fields into template.
It uses simple table layout. Type {tpl.fields} into template.
string | $id | name of template tag {ID} |
string | $sub | modificator (second part) of template tag name {ID.sub} |
mixed | $value | value of element going from Tpl->values array |
Reimplemented in Form.
print_Element | ( | $id, | |
$sub, | |||
$value | |||
) |
This function is called for each template tag when it is printed.
You can redefine this function in descendant and add your own element types.
string | $id | name of template tag {ID} |
string | $sub | modificator (second part) of template tag name {ID.sub} |
mixed | $value | value of element going from Tpl->values array |
print_Env | ( | $id, | |
$sub, | |||
$value | |||
) |
Print value from url (from _GET array).
Use in template like this: {GET.variable}.
string | $id | name of template tag {ID} |
string | $sub | modificator (second part) of template tag name {ID.sub} |
mixed | $value | value of element going from Tpl->values array |
print_Link | ( | $id, | |
$sub, | |||
$value | |||
) |
Create html link.
You can use 'popup' for popup window.
string | $id | name of template tag {ID} |
string | $sub | modificator (second part) of template tag name {ID.sub} |
mixed | $value | value of element going from Tpl->values array |
print_Number | ( | $id, | |
$sub, | |||
$value | |||
) |
Print numeric $value.
Perform numeric formatting.
string | $id | name of template tag {ID} |
string | $sub | modificator (second part) of template tag name {ID.sub} |
mixed | $value | value of element going from Tpl->values array |
print_String | ( | $id, | |
$sub, | |||
$s | |||
) |
Print string $value.
It supports string formatting, string crop, date formating, tooltip etc. See Template tags implemented by class Tpl for details.
string | $id | name of template tag {ID} |
string | $sub | modificator (second part) of template tag name {ID.sub} |
mixed | $value | value of element going from Tpl->values array |
setAttr | ( | $id, | |
$value, | |||
$value2 = null |
|||
) |
Set attribute globally for template elements.
string | $id | Element/Attribute id |
string | $value | Attribute id/Attribute value |
string | $value2 | Attribute value |
setFields | ( | $fields | ) |
Show only this $fields in template (using tag {grid.fields} or {form.fields}).
array | $fields | list of field (element) ids |
|
protected |
|
protected |
Name of the session variable where template values are stored.