Categories > TinyButStrong general >

MergeBlock problems - suddenly started happening

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: lauren
Date: 2012-04-01
Time: 19:51

MergeBlock problems - suddenly started happening

hi

not sure if this is something with PHP 5.4 or something else but the following has suddenly started breaking as described:

the PHP file sections of interest:
$region_id = getvarint("region_id");   // "getvarint" is a function i wrote that works - i use it in all my projects - the correct value is returned
include_once("../common/tbs_class.php");
$TBS = new clsTinyButStrong;
$TBS->MethodsAllowed = true;
$TBS->LoadTemplate("vehicle_escort.tpl","UTF-8");
$TBS->MergeBlock("rg","mysql","select region_id,name from tbl_regions order by name");
$TBS->Show();

function do_rgs($block,$row,$recnum)
{
    global $region_id;
    $row['sel'] = ($region_id == $row['region_id'] ? "selected" : "");
}

the template section of interest:
<label for="region_id">Region</label><select id="region_id" name="region_id">
<option value='0'>Select Region...</option><option value="[rg.region_id;block=option;ondata=do_rgs]" [rg.sel]>[rg.name]</option>
</select>


now this arrangement would always draw the select list with the correct option selected based on whether it is the currently selected region_id

suddenly it has stopped working altogether, and spitting out a bunch of messages so:
TinyButStrong Error in field [rg.sel...]: item 'sel' is not an existing key in the array. This message can be cancelled using parameter 'noerr'.


anybody have any clues wht might be wrong here?

i am running debian with PHP 5.4.0 - i did find other stuff has changed in PHP 5.4.0, for example, they now have a built in "hex2bin" function, so other changes are possible i guess although i have no idea if this is the cause, or what would be breaking inside of TBS

thanks
By: Skrol29
Date: 2012-04-02
Time: 01:05

Re: MergeBlock problems - suddenly started happening

Hi Lauren,

I've tested your snippet and I had the same behavior as you. I had the error message with PHP 3.4, but now with PHP 3.3.

The problem is in your do_rgs() function. You must replace:
function do_rgs($block,$row,$recnum)
with:
function do_rgs($block,&$row,$recnum)

The difference is the "&" before the argument $row. This is noticed in the documentation.
In fact is it surprising that PHP 3.3 did not produce the error. It thing it should.

By: lauren
Date: 2012-04-02
Time: 07:02

Re: MergeBlock problems - suddenly started happening

oh wow how embarrassing!

thanks skrol - what an idiot mistake

i've written code that does this hundreds of times but for some reason didn't notice this instance despite staring at it for hours trying to debug semingly "bizarre" behaviour

:|