|
*.^.*.^.*.^.*.^.*.^.*.^.*.^.*.^.*.^.*.^.*.^.*.^.*.^.*.^.* TinyButStrong version 2.05 *.^.*.^.*.^.*.^.*.^.*.^.*.^.*.^.*.^.*.^.*.^.*.^.*.^.*.^.* |
|||||||
| 高亮显示新版本功能 |
应用于PHP4.0.6或更高版本的专业和易用模板引擎 |
| 主题 | 描述 |
| • 简介 | |
| 基本原理 | |
| 安装 | |
| 小示例 | |
| • PHP 方面 | |
| • 开始 | |
| 方法 LoadTemplate() | 从文件加载模板内容 |
| 方法 MergeBlock() | 将部分数据源合并入模板 |
| 方法 Show() | 自动处理和显示结果 |
| • 高级 | |
| 方法 CacheAction() | 为合并结果激活缓存系统 |
| 方法 GetBlockSource() | 返回定义块的源数据 |
| 方法 MergeField() | 把一个特定的字段和一个值合并(用一个值替换掉原模板里的值,后译) |
| 方法 MergeNavigationBar() | 合并入导航栏 |
| 方法MergeSpecial() | 合并自动字段, PHP 变量, 和其它... |
| 特性 Render | 改变合并的结尾选项 |
| 特性 Source | 返回这个结果的当然内容 |
| 特性 TplVars | 返回模板变量 |
| 添加一个数据源类型 | 生成一个 TBS 认可的新数据库类型 |
| 面向对象编程 (OOP) | 使 TBS 友好支持 OOP |
| • HTML 方面 | |
| • TBS 字段 | |
| 定义和语法 | |
| 参数 | |
| Var 字段 | |
| 特定 Var 字段 | |
| • TBS 块 | |
| 定义和语法 | |
| 参数 | |
| 闭合的块 | |
| 连续显示 (应用于栏) | |
| 动态查询 / 子块 | |
| 显示导航条(分页?) | |
| • 混合 | |
| 自动的字段和块 | |
| 子模板 | |
| 有条件的显示汇总 | |
| • 概要 | |
| TBS 字段的参数 | |
| TBS 块的参数 | |
| 分页导航的字段和参数 | |
| 特殊的字段名和块名 |
| 1. | 复制文件 tbs_class.php 到你网站的目录文件夹. |
| 2. | 在PHP程序的开头,加入下面这一行: include_once('tbs_class.php'); $TBS = new clsTinyButStrong ; 备注: 如果 TBS 文件 tbs_class.php 在不同的目录, 你需要指定它的路径. |
| Html 模板 | Php 程序 | 结果 |
| <html> <body> [var.message] </body> </html> |
<? include_once('tbs_class.php'); $TBS = new clsTinyButStrong ; $TBS->LoadTemplate('template.htm') ; $message = 'Hello' ; $TBS->Show() ; ?> |
<html> <body> Hello </body> </html> |
| Html 模板 | Php 程序 | 结果 |
| <table> <tr><td>[blk.val;block=tr]</td></tr> </table> |
<? include_once('tbs_class.php'); $TBS = new clsTinyButStrong ; $TBS->LoadTemplate('template.htm') ; $list = array('X','Y','Z') ; $TBS->MergeBlock('blk',$list) ; $TBS->Show() ; ?> |
<table> <tr><td>X</td></tr> <tr><td>Y</td></tr> <tr><td>Z</td></tr> </table> |
| 参数 | 描述 |
| File | 使用本地或绝对路径加载文件. |
| HtmlCharSet | 可选. 指定Indicates the character encoding
(charset) to use for Html conversion of the data when they will be merged.
It should be the same as the charset of the template. The default value is
'' (empty string) which is equivalent to
'ISO-8859-1' (Latin 1). 假如模板使用一个特殊的字符集,那么你需要给这个字符集指出html值. 在 Html 页面中, 字符集往往放在文件的开头处, 属于<Meta>标签的'content' 部分. TBS 支持PHP 函数 htmlentities() 所支持的所有字符集. 例如: 'BIG5' (繁体中文) 或'EUCJP' (日文). |
| 参数 | 描述 | ||||||||
| BlockName | 指定合并时TBS 块 名. 一个数据源可以复制为几个块,只要使用逗号分隔块名. |
||||||||
| Source |
指定合并时的数据源. | ||||||||
| Query | 可选. 指定返回合并记录的 SQL 声明.(原文:Indicates the SQL statement which returns the records to merge.) 根据数据源类型,显示下表中可能出现的值. |
||||||||
| PageSize | 可选. 此参数仅在定义分页模式后才可用. 指定一页显示多少条记录. |
||||||||
| PageNum | 可选. 此参数仅在定义分页模式后才可用. 指定显示哪一页. 第一页是 1. 如果指定为-1 将显示最后一页. |
||||||||
| RecCount | 可选. 此参数仅在定义分页模式 后才可用. 他允许调整MergeBlock()方法返回的数字结果.(原文:It allows to adjust the calculation of the number of records returned by the MergeBlock() method.)
使用此参数为了计算和保存记录总数. 例子: if (isset($_POST['nbr_rec'])) { $nbr_rec = $_POST['nbr_rec'] ; } else { $nbr_rec = -1 ; } $nbr_rec = $TBS->MergeBlock('blk1',$cnx_id,'select * from t_country',$p_size,$p_num,$nbr_rec); |
| 数据源类型 | Source | Query |
| Text (*) | 关键字 'text' | A text |
| Number (*) | 关键字'num' | A number or a special array (see below) |
| Clear (*) | 关键字'clear' | - |
| Conditional (*) | 关键字'cond' | - |
| PHP Array (*) | 一个PHP数组 | - |
| 关键字'array' | A Php Array | |
| 关键字'array' | A string that represents an array contained or nested in a PHP global variable (see below) | |
| MySQL | 一个 MySql 连接标识符或关键字 'mysql' | An SQL statement |
| 一个 MySql 结果标识符 | - | |
| PostgreSQL | 一个 PostgreSql 连接标识符 | An SQL statement |
| 一个 PostgreSql 结果标识符 | - | |
| SQLite | 一个 SQLite 连接标识符 | An SQLite statement |
| 一个 SQLite 结果标识符 | - | |
| custom |
A keyword, an object or a resource identifier not
mentioned in this table. See the chapter 'adding a data source type'. |
An SQL statement or something else. |
| arg Query | 返回记录集 |
| Number: | 数字必须大于等于0. 返回记录集由数列 'val' 从1至指定数字组成. |
| Array: | 这个数组须由 'min', 'max' 和 'step'组成. 返回记录集将由数列 'val' 从 'min'到'max'的值组成. 示例: array('min'->101,'max'->150) 将显示从101至150的50个块. |
| 示例: | ['key1']=>value1 ['key2']=>value2 ... |
| 示例: | [0] => (['column1']=>value1-0 ;
['column2']=>value2-0 ; ...) [1] => (['column1']=>value1-1 ; ['column2']=>value2-1 ; ...) [2] => (['column1']=>value1-2 ; ['column2']=>value2-2 ; ...) ... |
| 参数 | 描述 |
| CacheId | 缓存文件的Unic id. 必需是一个字符, 它将被做为文件名使用. |
| Action/MaxAge | 让action执行的操作. 必需是 TinyButStrong's 定义的值. 参见下表了解更多可用指令的细节. 默认值为 3600 ,与之对应的是1小时内自动备份(译不准,原文:wich correspond to an automatic backup with a max age of 1 hour) |
| Dir | 可选. 指定缓存文件保存的路径. 默认为执行脚本的目录 即./ |
| 动作 | 描述 | ||||
| x >=0
(正数) |
最大寿命自动模式(Automatic Mode with max-age):
| ||||
| TBS_CACHENOW | 保存当前合并结果到与 CacheId 相对应的缓存文件. CacheAction() 返回 false. |
||||
| TBS_CACHELOAD | 以 CacheId 加载对应的缓存文件. 假如缓存文件存在并加载成功 CacheAction() 返回 true , 否则返回 false. |
||||
| TBS_DELETE | 删除 CacheId 相对应的缓存文件. 你可以删除一个目录下的所有缓存文件,你只要指定 CacheId 为 '*'. CacheAction() 返回 false. |
||||
| TBS_CACHEONSHOW | 开始从 CacheId 相对应的缓存文件 "显示缓存" CacheAction() 返回 false. |
||||
| TBS_CANCEL | 取消 "显示缓存" 无论是什么 CacheId. CacheAction() 返回 false. |
||||
| TBS_CACHEGETAGE | 返回缓存文件寿命秒数.文件不存在则返回 false. | ||||
| TBS_CACHEGETNAME | 返回与 CacheId 相对应的缓存文件名. 即使文件不存在也返回. |
||||
| TBS_CACHEISONSHOW | 假如 "显示缓存" 可用,返回 true , 否则, 返回 false. |
| 参数 | 描述 |
| BlockName | 搜索的块名. |
| Sections | 可选. 默认值为 False. 如果参数设置为 True 方法将返回一个包含指定块所有部分定义的数组. 第一个部分将被返回到数组里的 item [1]. |
| 参数 | 描述 |
| BaseName | TBS Fields的基础名. 比如 'account'. |
| X | 需要显示的值或代表一个用户函数的字串. |
| FunctionMode | 指定显示值由一个用户函数给出. 默认值为 false. 假如参数设为 true, X 必须为用户函数名的字串. 此函数必须存在且拥有以下描述的语法. |
语法: $TBS->MergeNavigationBar(string NavName, mix Options, int PageNum [, int RecCount, int PageSize])
| 参数 | 描述 | ||||||||||
| NavName | 导航栏的名字. |
||||||||||
| Options | 可以让你参强制运行一此导航栏选项. 这些选项同样可以定义在模板的块参数中. 但假如你将这此选项也放在 MergeNavigationBar(),他们也将被强制运行. 此参数可为空 ('', 0 或者 null), 也可是一个数字或数组. 假如是一个数字, 表示显示的页数. 假如是一个数组, 表示包含如下项:
| ||||||||||
| PageNum | 当前显示的页面数值. 第一页为1. 要表示最后一页可以使用-1. |
||||||||||
| RecCount | 可选. 默认值为 -1. 设置记录总数. 但当你不知道这个数字时,请将它设为-1. 此参数仅用来计算导航栏的最后一页的值. |
||||||||||
| PageSize | 可选. 默认值为1. 表示每页的记录数. 它要配合 RecCount 使用,来计算导航栏的最后一页的值. |
| 值 | 描述 |
| 'var' | 替换所有Var fields. |
| 'onload' |
替换所有onload fields. |
| 'onshow' | 替换所有onshow fields. |
| 常量 | 描述 |
| TBS_NOTHING | 表明在合并结束前不进行任何动作. |
| TBS_OUTPUT | 表明让TBS使用PHP的echo命令将合并结果显示出来. |
| TBS_EXIT | 表明脚本在合并结束后退出. |
| 参数 | 描述 |
| $Source | 与传递到 MergeBlock() 方法的参数相同. |
| $Query | 与传递到 MergeBlock() 方法的参数相同. |
| 参数 | 描述 |
| $Rs | 从tbsdb_customdb_open() 函数返回的记录集标识符. |
| $RecNum | 可选. 预期的记录数. 第一个是数字 1. |
| 参数 | 描述 |
| $Rs | 从tbsdb_customdb_open() 函数返回的记录集标识符. |
| 特征 | 示例 |
| Var Fields | [var.~prop1] ... [var.~.key1.prop1] ... [var.~meth1] ... [var.~prop2.subprop] |
| Parameter ondata | [blk1.column1;block=tr;ondata=~meth_ondt] |
| Parameter onformat | [blk1.column2;onformat=~meth_onfrm] |
| MergeField() method | $TBS->MergeField('fldname','~meth_MrgFld',true); |
| Custom Data Functions (*) | $TBS->MergeBlock('blk1','~mydb','SELECT * FROM t_table'); |
| Custom Html conversion function | $TBS->LoadTemplate('mytemplate.htm','=~meth_htmlconv'); |
| Element | Description |
| FieldName | The name of the Field. Warning: names that begin with var. , onload and onshow are reserved. They are respectively used for Var fields, and Automatic fields. |
| params | Optional. One or more parameters from the list
below and separated with ';'. Some parameters can be set to a value using the equal sign '='. Example: frm=0.00 If the value contains spaces or semicolons, you can use single quotes. Example: frm='0 000.00'. It is possible to embed TBS fields. It means you can write this: [var.v1; if [var.v2]=1]. But: - for Var fields, you have to make sure that v2 will be merged before v1. - for block fields, you have to make sure that column v2 is before column v1. |
| Parameter | Description | ||||||||||||||||||||||||||||||||||||||||||||||
| htmlconv=val | Enables you to force or prevent the conversion
of the data item to Html text. The value val can be one of the following keywords:
| ||||||||||||||||||||||||||||||||||||||||||||||
| . (dot) | If the data item is empty, then an unbreakable space is displayed. Useful for cells in tables. | ||||||||||||||||||||||||||||||||||||||||||||||
| ifempty=val | If the data item is empty, then it is replaced with the specified value. | ||||||||||||||||||||||||||||||||||||||||||||||
| magnet=tag | Assign a magnet Html tag to the TBS field. A
magnet tag is kept as is when the field has a value, and is deleted when
the field is null or empty string. Example: By default, the magnet Html tag should
be a pair of opening-closing tags (like <a></a>) which first tag is placed
before the TBS fields. But this can be changed using parameter mtype (see below). (<a href="[var.link;magnet=a]">click here</a>) Result for $link='www.tbs.com': (<a href="www.tbs.com">click here</a>) Result for $link='': () Remark: the parameters if then else are processed before parameter magnet. | ||||||||||||||||||||||||||||||||||||||||||||||
| mtype=val | To be used with parameter
magnet. Define the magnet type.
| ||||||||||||||||||||||||||||||||||||||||||||||
| selected | This parameter enables you to select an item for
a List, Radio buttons or Checkboxes placed into a Html form. You have to
ensure that items are created (merged) before the merge. Html List: Use the parameter selected without setting a value to it. The TBS
Field has to be placed within the list of values. When the TBS field is
merged it is deleted, but the item which has the same value as the field
will be selected. If the value is not found, a new item is added.
Radio buttons and Checkboxes: Use the parameter
selected with setting a value to it which is
the name of the Radio buttons or Checkboxes to process. The TBS Field has
to be placed within the form. When the TBS field is merged it is deleted,
but the item which has the same value as the field will be selected.
Multi-selection: For Lists, Radio buttons or
Checkboxes, you can make a multi-selection by giving a Php array as the
value of the TBS field.Bounds: By default the bounds for searching items to select are html tags <select> for List , and <form> for Radio buttons and Checkboxes. But you can change them using parameter selbounds (see below). | ||||||||||||||||||||||||||||||||||||||||||||||
| selbounds=tag | To be used with parameter selected. It enables you to change the search zone
for items to select by indicating a Html tag type. By default, this value
is select for a List, and form for Radio buttons and Checkboxes. Example: [town_id;selected=r_test;selbounds=div] In this example, items to select will be searched between <div> and </div> tags that surround the TBS field. | ||||||||||||||||||||||||||||||||||||||||||||||
| comm | This parameter enables you to widen the bounds
of the TBS Field up to the bounds of the commentary Html tag which
surround it. <!-- [myfield;comm] this is an example--> is strictly identical to [myfield] This is particularly useful for the template designing when you are using a Visual HTML Editor (such as Dreamweaver or FrontPage). | ||||||||||||||||||||||||||||||||||||||||||||||
| noerr | Avoid some of the TBS Error messages. When a message can be cancelled, it is mentioned in the message. | ||||||||||||||||||||||||||||||||||||||||||||||
| file=filename | Replace the field with the contents of the file.
Filename can be a
string or an expression built with Var
fields that returns the file path. How to use this parameter is detailed in the chapter Subtemplates. | ||||||||||||||||||||||||||||||||||||||||||||||
| script=filename | Execute the Php script just before replacing the
locator. Filename can be a string or an expression built with Var fields that returns the file path.
| ||||||||||||||||||||||||||||||||||||||||||||||
| subtpl | To be used with the parameter script or parameter onformat. Activate the subtemplate mode during the script or function execution. See chapter 'Subtemplates' for more details. | ||||||||||||||||||||||||||||||||||||||||||||||
| once | To be used with the parameter script. Cancel the script execution if it has previously been called. | ||||||||||||||||||||||||||||||||||||||||||||||
| getob | This parameter is deprecated because it can be
replaced with parameter subtpl. To be used with the parameter script. Indicates that the text displayed using the echo() command in the Php script replaces the value of the TBS Field. | ||||||||||||||||||||||||||||||||||||||||||||||
| if expr1=expr2 | Display the data item only if the condition is
verified, otherwise display nothing unless parameter then or else are
used. Supported operators are:
See parameters then and else for some examples. | ||||||||||||||||||||||||||||||||||||||||||||||
| then val1 | If the parameter if
is defined and its condition is verified, then the data item is replaced
with val1. Example: [var.image;if [val]='';then 'image0.gif'] | ||||||||||||||||||||||||||||||||||||||||||||||
| else val2 | If the parameter if
is defined and its condition is not verified, then the data item is
replaced with val2. Example: [var.error_id;if [val]=0;then 'no error';else 'error found'] | ||||||||||||||||||||||||||||||||||||||||||||||
| onformat=fct_name | Indicates the name of a user Php function that
will be executed before the merge of the field. The function fct_name must have the following syntax: function fct_name($FieldName,&$CurrVal,{&$CurrPrm,{&$TBS}}) { ... }
| ||||||||||||||||||||||||||||||||||||||||||||||
| protect=val | Enables you to protect or unprotect the data
item to be merged by replacing the characters '[' with their corresponding Html code '['. The value val can be one of the following
keywords: yes: (default value) data item is protected. no: data item is not protected. By default, all data merged with a template is protected except if it's a file inclusion. It is strongly recommended to protect data when it comes from free enter like on a forum for example. | ||||||||||||||||||||||||||||||||||||||||||||||
| max=val | Indicates the maximum number of characters to display. Beyond this limit, the data item is cut and an ellipsis (...) is added at the bottom. | ||||||||||||||||||||||||||||||||||||||||||||||
| frm=format | Specify a format to display a data item of type
date/time or numeric. For a numeric item, it is possible to use a
conditional format which changes depending on the sign of the value.
Date-time format: It is a VisualBasic like format. The following keywords are recognized:
Other characters are kept. It is possible to protect the strings inside by putting them between single or double quotes. Examples: [fld;frm=mm/dd/yyyy] will display 12/21/2002 [fld;frm='yyyy-mm-dd hh:nn:ss'] will display 2002-12-21 15:45:03 Numeric format: To define the decimal part, use an expression like '0x0...' where 'x' is the decimal separator , and '0...' is a continuation of zeros corresponding to the number of decimals. If there is no decimal, use the format '0.' (with a dot). To define a thousand separator, use an expression like '0z000x...' where 'z' is the thousand separator. If there is no decimal, use the format '0z000.' (with a dot). If the format contains the character '%', then the value to display will be multiplied by 100. The character '%' is displayed too. The numerical format may contain other strings. But only the expression with one or more zeroes placed to the right will be taken as a format, other characters will be kept. Examples:
Conditional formats: You have the possibility to define up to 4 conditional formats when the value is respectively positive, negative, zero or null (or empty string). Conditional formats must be separated by a '|' character. Each conditional format is optional. Examples:
| ||||||||||||||||||||||||||||||||||||||||||||||
| locale | To be used with the parameter frm. Indicates that the format specified with frm must display locale day and month's names. Locale informations can be set using the PHP function setlocale(). | ||||||||||||||||||||||||||||||||||||||||||||||
| tplvars | Enables you to define variables in the template that you can retrieve in the Php programm using TplVars property. Works only with onload automatic fields. |
| 名称 | 描述 |
| var..now | 服务器当前时间. |
| var..version | TinyButStrong当前版本号. |
| var..script_name | 当前执行的PHP文件名. |
| var..template_name | 最后加载的模板文件名. 它来自于 LoadTemplate() 方法. |
| var..template_date | 最后加载的模板文件的创建时间. |
| var..template_path | 最后加载的模板文件的路径. 来自于 LoadTemplate() 方法. |
| var..tplvars.* | 此值用在 TplVars
特性项中. ('*' 必须是数组中存在项的键值) |
| 参数 | 描述 | ||||||||
| extend=n extend=tag1,tag2,... |
为块定义更多的扩展标签.这个参数仅适用于关联语法或简化语法中.比如:它让你可以定义在一个两行表格上的块. 语法 1: 使用数字 n (正负都行) 为块定义 n 个下一对扩展标签. 标签名与参数 block 相同. 如果 n 为负数, 那么块将被反扩展,即扩展到前一对标签. 语法 2: 使用一个标签列表 为块定义下一对扩展标签. 标签为列表提供 . | ||||||||
| encaps=num | 指定参数 block 对应HTML标签的TBS标签的封装等级.默认值为 1. 例如:
上例中, 蓝色行在合并时将被复制,因为 'encaps=2'. 如果 'encaps=1' 或者参数没值, 那么在合并时被复制的将是桃红色行. |
||||||||
| comm | 这个参数使你能加宽TBS标签的范围到包含它的HTML注释标签里. <!-- [block1;block=tr;comm] 这是个例子--> 等同于 [block1;block=tr] 此参数非常适用于使用可视编辑器进行模板设计. |
||||||||
| nodata | 指定一个仅当没有数据合并时才显示的部分. 例如:
更多信息, 参见 'Sections of blocks'章节. |
||||||||
| headergrp=colname | 指定一个每次 colname
值变动时显示的 header 部分. colname 必须是一个由数据源返回的有效 column 名. 你可以使用不同columns定义若干 headergrp 部分. 放置次序 headergrp 部分在块可以修改结果. 更多部分, 请参见 'Sections of blocks'. |
||||||||
| footergrp=colname | 指定一个每次 colname 值变动时显示的footer部分. 参见 headergrp. | ||||||||
| splittergrp=colname | 指定一个每次 colname 值变动时显示的splitter部分. 参见 headergrp. | ||||||||
| parentgrp=colname | 指定一个每次 colname 值变动时显示的parent部分. 不同于其它的部分,一个 parentgrp 部分允许普通部分存在与其内.这是一个可以同时定义header 和 footer 部分的方法. | ||||||||
| serial | 指定块为连续主块. 更多信息, 参见章节 'serial display (in columns)'. |
||||||||
| p1=val1 | 用于动态查询. 所有在 MergeBlock() 方法形成的字串 '%p1%' 将被值 val1 代替. 了解更多, 参见章节 'dynamic queries / sub-blocks'. |
||||||||
| ondata=fct_name | 指定在块合并时需要执行的用户函数.函数会在每次获取数据源的时候被调用.你可以使用参数在记录合并前编辑.函数必须使用如下语法: function fct_name($BlockName,&$CurrRec,$RecNum) { ... }
function f_add_column($BlockName,&$CurrRec,$RecNum)
{ $CurrRec['len'] = strlen($CurrRec['text']); } | ||||||||
| onsection=fct_name | 小心使用此参数,因为有可能它将不再被将来的版本所支持. 它被用作兼容性用途,所以你应该使用更快的 ondata 参数. onsection 与 ondata 一样工作, 除了他的用户函数将在合并时每次去调用. So if your block contains header sections or conditional sections, then the function may be called several times for the same record. 函数语法: function fct_name($BlockName,&$CurrRec,&$DetailSrc,$RecNum) { ... } 参数 $DetailSrc 返回当前部分源 (读/写 ; 别忘记函数以&开头 ).. 假如此值为 '', 它将取消显示此记录. |
||||||||
| when expr1=expr2 | 标记此部分为条件部分,当条件被核实,一个条件部分才会被显示. 支持如下算式: | ||||||||