Categories > TinyButStrong general >

apply php function after/in merge block ?

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: sam
Date: 2011-02-26
Time: 20:18

apply php function after/in merge block ?

Hi,

where to put block=tr in the table ? i put that into any row and it still works.

One of my field returns seconds in the table. The output is from mergeblock.
To change that seconds into minutes using a php function, where to apply that ?


Thanks,
Sam
By: sam
Date: 2011-02-26
Time: 20:19

Re: apply php function after/in merge block ?

I mean the data is already displayed in the page.
How to do post-processing?


Thanks
By: sam
Date: 2011-02-26
Time: 20:21

Re: apply php function after/in merge block ?

Please ignore this question.

I found solution here: http://www.tinybutstrong.com/forum.php?thr=2099
By: sam
Date: 2011-02-26
Time: 20:43

Re: apply php function after/in merge block ?

$Records = USER::LastRecords($accid,10);

$TBS = new clsTinyButStrong;


$TBS->LoadTemplate('rcds_.php');

$TBS->MergeField('rcds.time','sec2mins',true);


function sec2mins($dur) {
    $rec = $dur/60;
    return $rec;
}

$TBS->MergeBlock('rcds',$Records);

$TBS->Show();



But I get 0 in the output.
By: Skrol29
Date: 2011-02-26
Time: 22:10

Re: apply php function after/in merge block ?

Your
$TBS->LoadTemplate('rcds_.php');
is suspicious:why do you load a PHP file as a template?

And the sec2mins() function has not the expected syntax for a MergeField().
See http://www.tinybutstrong.com/manual.php#php_mergefield
By: sam
Date: 2011-02-27
Time: 09:19

Re: apply php function after/in merge block ?

Hi,

.php is just for test. Sorry for that.

Example has:

$TBS->MergeField('ml','m_multilanguage',true);
...
function m_multilanguage($Subname) {
  global $lang_id;
  $rs = mysql_query("SELECT text_$lang_id AS txt FROM t_language WHERE key='$Subname");
  $rec = mysql_fetch_array($rs);
  return $rec['txt'] ;
}

I tried

$TBS->MergeField('rcds.time','sec2mins',true);

$TBS->MergeField('time','sec2mins',true); // or $TBS->MergeField('rcds.time','sec2mins',true);

function sec2mins($Subname) {
    $rec = $Subname/60;
    return $rec;
}


Thanks,.
By: sam
Date: 2011-02-27
Time: 09:22

Re: apply php function after/in merge block ?

"When the function is called, its argument $Subname has for value the suffix of the field's name (example: for a field named 'ml.title', $Subname will have the value 'title')"

Does this mean i have to do if $Subname = "time" // then $seconds = $PrmLst ??

By: Skrol29
Date: 2011-02-28
Time: 23:22

Re: apply php function after/in merge block ?

MergeField('rcds.time','sec2mins',true) will scan for each TBS fields prefixed with [rcds.time] and merge them with the result of sec2mins() which is supposed to return a single value.
The field [rcds.time.xxx] will be replaced by the value returned by sec2mins('xxx').

It seems that you more need a MergeBlock(). You can perform the division on a field using parameter "ope=div:60" or using parameter "onformat" with a custom function.