Thursday, January 12, 2012

Writing Table Headers with PHPTAL Repeat Key

Writing Table Headers with PHPTAL Repeat Key

Not immediately obvious to me, the PHPTAL manual says:
"Within a loop, you can access the current loop information (and that of its parent for nested loops) using specific repeat/* paths."

This means that instead of writing table header values in the template, you can use the key in your table data.
$sql = " SELECT SUM(hours_regular) AS RT, SUM(hours_overtime) AS OT...


PHPTAL manual says:

Within a loop, you can access the current loop information (and that of its parent for nested loops) using specific repeat/* paths.

repeat/item/key : returns the item's key if some/result is an associative resource (index otherwise)
repeat/item/index : returns the item index (0 to count-1)
repeat/item/number : returns the item number (1 to count)
repeat/item/even : returns true if item index is even
repeat/item/odd : returns true if item index is odd
repeat/item/start : returns true if item is the first one
repeat/item/end : returns true if item is the last one
repeat/item/length : returns the number of elements in some/result

"item" depends on the receiver variable defined in tal:repeat expression.


http://phptal.org/manual/en/#tal-repeat

No comments: