pclib  2.3.2
Lightweight PHP framework
Public Member Functions | Data Fields | Protected Member Functions | Protected Attributes
Tpl Class Reference

Template engine. More...

Inheritance diagram for Tpl:
BaseObject Form Grid Layout

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...
 
 set ($keystr, $value)
 Set attributes for template elements. 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)
 Use default template for displaying database table content.
 
 compute ($id)
 Return computed value of element $id. More...
 
 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...
 
 getPopup ($id, $attr, $url)
 Generate javascript code for popup window. More...
 
 getItems ($id)
 Load lookup table for elements such as bind, select, check or radio. 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...
 
 addEvent ($name, $callback)
 Add event handler to $object->$name property. More...
 
 toArray ()
 Convert object to array. More...
 

Data Fields

 $onInit
 Occurs on template initialization. More...
 
 $onLoad
 Occurs after template is loaded and parsed. More...
 
 $onBeforeOut
 Occurs before output. More...
 
 $onAfterOut
 Occurs after output. More...
 
 $name
 Name of the template. More...
 
 $elements = array()
 Array of elements loaded from <?elements ? > section.
 
 $values = array()
 Array of template values. More...
 
 $db
 var Db
 
 $translator
 var Translator
 
 $router
 var Router
 
 $useXhtml = false
 Generate XHTML code. More...
 
 $escapeHtmlFunction
 Function for escaping html in template values. More...
 
- Data Fields inherited from BaseObject
 $onNewInstance
 Occurs when new instance of the class is created. More...
 
 $onMissingMethod
 Occurs when called method does not exist. More...
 
 $serviceLocator
 var function() Return service object when requested with service(). More...
 

Protected Member Functions

 getAttr ($id, $attr)
 Return attribute of element $id. More...
 
 getVariable ($id)
 Get template variable tvar... More...
 
 getRowNo ()
 Return row number of the current block. More...
 
 createFromTable ($tableName, $templatePath)
 Use default template for displaying database table content.
 
 trPrintElement ($elem)
 Print element in table layout. More...
 
 getUrl ($elem)
 Return url for the element (button, link) with completed parameters. More...
 
 formatDate ($dtstr, $fmt= '')
 DATABASE DATE => HUMAN DATE (in strftime() format) More...
 
 formatStr ($s, $fmt)
 Format string $s according format $fmt.
 
- Protected Member Functions inherited from BaseObject
 fireEvent ($name, array $args=array())
 Run all event handlers in $object->$name property. More...
 
 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. More...
 
 $config = null
 Link to array of configuration parameters. More...
 
 $document
 Document array - It contains parsed template. More...
 
 $parser
 var TplParser
 

Additional Inherited Members

- Static Public Member Functions inherited from BaseObject
static defaults ()
 Set or retireve default parameters of the object. More...
 

Detailed Description

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.

Constructor & Destructor Documentation

__construct (   $path = '',
  $sessName = '' 
)

Load and parse template file.

Parameters
string$pathFilename of template file
string$sessNameWhen set, object is stored in session as $sessName

Member Function Documentation

compute (   $id)

Return computed value of element $id.

disable ( )

Disable (hide) tag or block $name.

Parameters
array|listof tag names
enable ( )

Enable (show) or disable (hide) tag or block $name.

$tpl->enable('tag'); $tpl->enable('tag1','tag2'); $tpl->enable('tag', false);

Parameters
array|listof tag names
bool$valEnable? true|false
formatDate (   $dtstr,
  $fmt = '' 
)
protected

DATABASE DATE => HUMAN DATE (in strftime() format)

See also
strftime()
getAttr (   $id,
  $attr 
)
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.

Parameters
string$idElement Id
Returns
string $val Element value
getItems (   $id)

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;

Parameters
int$ididentificator of element
Returns
array $items
getPopup (   $id,
  $attr,
  $url 
)

Generate javascript code for popup window.

Parameters
string$attrpopup attribute of element (Example: popup "600x400+100+100")
string$urlurl of page to open
Returns
string $js javascript window code
getRowNo ( )
protected

Return row number of the current block.

getUrl (   $elem)
protected

Return url for the element (button, link) with completed parameters.

getValue (   $id)

Return value of element $id.

Parameters
string$idElement Id
Returns
string $val Element value
getVariable (   $id)
protected

Get template variable tvar...

html (   $block = null)

Return html output of the template populated with content.

Parameters
string$blockIf set, only html of the block $block will be returned.
load (   $path)

Load template file.

Parameters
string$pathfilename of template file
See also
loadString()
loadString (   $s)

Load string $s as template.

Useful, if you need read template from another source than filesystem.

Parameters
string$sstring containing template source
out (   $block = null)

Display template populated with content.

Replace all tags in template with $values, perform any formatting and callback functions for the $elements and write output.

Parameters
string$blockIf set, only block $block will be printed.
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)

Template element handler
Get element definition from Tpl->elements and write element value from Tpl->values into template.
Note
This function comes in form print_*() where "*" is usually TAGNAME which can be used in <?elements ?> section of template.
Parameters
string$idname of template tag {ID}
string$submodificator (second part) of template tag name {ID.sub}
mixed$valuevalue 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.

Template element handler
Get element definition from Tpl->elements and write element value from Tpl->values into template.
Note
This function comes in form print_*() where "*" is usually TAGNAME which can be used in <?elements ?> section of template.
Parameters
string$idname of template tag {ID}
string$submodificator (second part) of template tag name {ID.sub}
mixed$valuevalue of element going from Tpl->values array
print_Block (   $block)

Print template block.

Block is template section marked with:

{block name}
html code...
{/block}

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.

Template element handler
Get element definition from Tpl->elements and write element value from Tpl->values into template.
Note
This function comes in form print_*() where "*" is usually TAGNAME which can be used in <?elements ?> section of template.
Parameters
string$idname of template tag {ID}
string$submodificator (second part) of template tag name {ID.sub}
mixed$valuevalue 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} or {tpl.control} into template.

Template element handler
Get element definition from Tpl->elements and write element value from Tpl->values into template.
Note
This function comes in form print_*() where "*" is usually TAGNAME which can be used in <?elements ?> section of template.
Parameters
string$idname of template tag {ID}
string$submodificator (second part) of template tag name {ID.sub}
mixed$valuevalue of element going from Tpl->values array
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.

Template element handler
Get element definition from Tpl->elements and write element value from Tpl->values into template.
Note
This function comes in form print_*() where "*" is usually TAGNAME which can be used in <?elements ?> section of template.
Parameters
string$idname of template tag {ID}
string$submodificator (second part) of template tag name {ID.sub}
mixed$valuevalue 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}.

Template element handler
Get element definition from Tpl->elements and write element value from Tpl->values into template.
Note
This function comes in form print_*() where "*" is usually TAGNAME which can be used in <?elements ?> section of template.
Parameters
string$idname of template tag {ID}
string$submodificator (second part) of template tag name {ID.sub}
mixed$valuevalue of element going from Tpl->values array
print_Link (   $id,
  $sub,
  $value 
)

Create html link.

You can use 'popup' for popup window.

Template element handler
Get element definition from Tpl->elements and write element value from Tpl->values into template.
Note
This function comes in form print_*() where "*" is usually TAGNAME which can be used in <?elements ?> section of template.
Parameters
string$idname of template tag {ID}
string$submodificator (second part) of template tag name {ID.sub}
mixed$valuevalue of element going from Tpl->values array
print_Number (   $id,
  $sub,
  $value 
)

Print numeric $value.

Perform numeric formatting.

Template element handler
Get element definition from Tpl->elements and write element value from Tpl->values into template.
Note
This function comes in form print_*() where "*" is usually TAGNAME which can be used in <?elements ?> section of template.
Parameters
string$idname of template tag {ID}
string$submodificator (second part) of template tag name {ID.sub}
mixed$valuevalue 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.

Template element handler
Get element definition from Tpl->elements and write element value from Tpl->values into template.
Note
This function comes in form print_*() where "*" is usually TAGNAME which can be used in <?elements ?> section of template.
Parameters
string$idname of template tag {ID}
string$submodificator (second part) of template tag name {ID.sub}
mixed$valuevalue of element going from Tpl->values array
set (   $keystr,
  $value 
)

Set attributes for template elements.

$keystr can be 'element/attribute' or 'block/element/attribute'. If you need set all elements in block, you can use wildcard: 'block/ * /attribute'. Also you can select elements with some attr. value: 'attr=value/attribute'

Parameters
string$keystrAttribute specification (with wildcards)
string$valueValue assigned to attribute.
trPrintElement (   $elem)
protected

Print element in table layout.

See also
print_class();

Field Documentation

$app
protected

var App Link to application object.

$config = null
protected

Link to array of configuration parameters.

$document
protected

Document array - It contains parsed template.

$escapeHtmlFunction

Function for escaping html in template values.

$name

Name of the template.

$onAfterOut

Occurs after output.

$onBeforeOut

Occurs before output.

$onInit

Occurs on template initialization.

$onLoad

Occurs after template is loaded and parsed.

$sessName
protected

Name of the session variable where template values are stored.

See also
loadSession(), saveSession()
$useXhtml = false

Generate XHTML code.

$values = array()

Array of template values.


The documentation for this class was generated from the following file: