Categories > TinyButStrong general >

Warning Scalar Value in MergeBlock with event function

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: wspras
Date: 2011-02-22
Time: 16:09

Warning Scalar Value in MergeBlock with event function

Hi ,
I have error PHP
<code>Warning: Cannot use a scalar value as an array in \wspras\questions\simulasi.php  on line 167</code>


HTML Script is:
<code>
<table>
<tr><td>
    <div style="text-align:justify;">[mb.TEACHER;ondata=event_modul;block=tr;htmlconv=no]</div>
     </td>
</tr>

<tr>
   <td ><strong>[+sb.NOMOR;htmlconv=no+].</strong>&nbsp;&nbsp;</td>
   <td >[+sb.SCHOOL;block=tr;p1=[+mb.$+];htmlconv=no+]</td>
</tr>
<tr>
    <td><strong>[+sb.NOMOR;htmlconv=no+].</strong>&nbsp;&nbsp;</td>
    <td >[+sb.SCHOOL;block=tr;htmlconv=no+]</td>
</tr>


</table>
</code>

PHP Script is:
<code>
//merger block
$TBS->MergeBlock('mb','array','ByTeacher');
$TBS->MergeBlock('sb','array','ByTeacher[%p1%][HISTORY]');


//on event function merge block
function event_modul($BlockName,&$CurrRec,$RecNum){
$CurrRec['TEACHER'] = htmlNormal($CurrRec['TEACHER']); //htmlNormal fixed some string and this LINE 167
}
</code>

How solution for this problem ?

Thanks.

Regard,

wspras
By: Skrol29
Date: 2011-02-22
Time: 22:56

Re: Warning Scalar Value in MergeBlock with event function

Hi,

It seams that $CurrRec in event_modul() is not always an array as you expect. $CurrRec is the item exctracted by TBS from the global variable $ByTeacher.
You can check the contents of $ByTeacher with the code:
var_export($ByTeacher); exit;

You should also check the $CurrRec variable in event_modul() in order to catch when it is not an array.

By the way, I've noticed in your HTML template that the main block "mb" is not embedding the sub-block "sb" as we could guess. It is also strange that you've defined the "sb" block with two sections while the second one seems quite the same as the first one.
By: wspras
Date: 2011-02-23
Time: 00:48

Re: Warning Scalar Value in MergeBlock with event function

Hi ,

Result array $ByTeacher :
array (
  0 =>
  array (
    'TEACHER_ID' => '46',
    'TEACHER' => 'Ronaldo',
    'AGE' => 26,
    'HISTORY' =>
    array (
      0 =>
      array (
        'TEACHER_ID' => '46',
        'SCHOOL_ID' => '1',
        'NAME' => 'Univer 1',
        'FEEDBACK' => New teacher',
      ),
      1 =>
      array (
        'TEACHER_ID' => '46',
        'SCHOOL_ID' => '3',
        'NAME' => 'Univer 2',
        'FEEDBACK' => New teacher',
      ),
    ),
  ),

..etc


Yes, i am changed HTML

<table>
<tr><td colspan="2">
<div style="text-align:justify;">[mb.TEACHER;ondata=event_modul;block=tr;htmlconv=no]</div>
     </td>
</tr>

<tr>
   <td ><strong>[sb.SCHOOL_ID;htmlconv=no].</strong></td>
   <td >[sb.NAME;block=tr;p1=[mb.$];htmlconv=no]</td>
</tr>
</table>


Then, i am tested this without use event_modul()

function event_modul($BlockName,&$CurrRec,$RecNum){
//$CurrRec['TEACHER'] = htmlNormal($CurrRec['TEACHER']); //htmlNormal fixed some string and this LINE 167
}

OK, TBS can display my data with very good.

But, when i am trying uncomment LINE 167 ,

Warning: Cannot use a scalar value as an array in \wspras\questions\simulasi.php  on line 167

Can help again?

Regard,

wspras
By: Skrol29
Date: 2011-02-23
Time: 01:20

Re: Warning Scalar Value in MergeBlock with event function

I don't think it comes from TBS. Can you try the following for debugging ?
function event_modul($BlockName,&$CurrRec,$RecNum) {
  echo "debug: ".var_export($CurrRec,true)."\r\n";
  //$CurrRec['TEACHER'] = htmlNormal($CurrRec['TEACHER']); //htmlNormal fixed some string and this LINE 167
}
and double check that $CurrRec has the same name everywhere in the function..
By: wspras
Date: 2011-02-23
Time: 02:21

Re: Warning Scalar Value in MergeBlock with event function

Hi Skrol,

After this
echo "debug: ".var_export($CurrRec,true)."\r\n";

Result :

<html><head></head><body>debug: true
debug: true
debug: true
debug: true
debug: true
</body></html>

$CurrRec type is Boolean?

by the way. for readable HTML little fixed

<table>
<tr>
    <td colspan="2">
    <div style="text-align:justify;">[mb.TEACHER;ondata=event_modul;block=tr;htmlconv=no]</div>
    <table>    
    <tr>
       <td ><strong>[sb.SCHOOL_ID;htmlconv=no].</strong>
       <td >[sb.NAME;block=tr;p1=[mb.$];htmlconv=no]</td>
    </tr>
    </table>
   </td>
</tr>
</table>

Oy, this $ByTeacher


// Create data
$ByTeacher[0] = array('TEACHER_ID'=>'1'  ,'TEACHER'=>'Ronaldo','AGE'=>29);
$ByTeacher[0]['HISTORY'][] = array('TEACHER_ID'=>'1','SCHOOL_ID'=>'23','NAME'=>'University 1','FEED_BACK'=>'New Teacher');
$ByTeacher[0]['HISTORY'][] = array('TEACHER_ID'=>'1','SCHOOL_ID'=>'20','NAME'=>'University 2','FEED_BACK'=>'New Teacher');
$ByTeacher[1] = array('TEACHER_ID'=>'2'  ,'TEACHER'=>'Winardo','AGE'=>31);
$ByTeacher[1]['HISTORY'][] = array('TEACHER_ID'=>'2','SCHOOL_ID'=>'23','NAME'=>'University 5','FEED_BACK'=>'New Teacher');
$ByTeacher[1]['HISTORY'][] = array('TEACHER_ID'=>'2','SCHOOL_ID'=>'23','NAME'=>'University 6','FEED_BACK'=>'New Teacher');
$ByTeacher[2] = array('TEACHER_ID'=>'3'  ,'TEACHER'=>'Chelsea','AGE'=>25);
$ByTeacher[2]['HISTORY'][] = array('TEACHER_ID'=>'3','SCHOOL_ID'=>'23','NAME'=>'University 7','FEED_BACK'=>'New Teacher');
$ByTeacher[2]['HISTORY'][] = array('TEACHER_ID'=>'3','SCHOOL_ID'=>'23','NAME'=>'University 8','FEED_BACK'=>'New Teacher');
$ByTeacher[2]['HISTORY'][] = array('TEACHER_ID'=>'3','SCHOOL_ID'=>'23','NAME'=>'University 9','FEED_BACK'=>'New Teacher');

Full code : http://www.4shared.com/file/GI1sIK0a/test-tbs-teacher.html

I have started from Example of subblocks in TBS, then i modified example
when added event_function (in dynamic HTML) , same error show up.

How about this problem?

Thanks again.

By: Skrol29
Date: 2011-02-23
Time: 10:48

Re: Warning Scalar Value in MergeBlock with event function

Hi,

Thank you very much for your snippet download for reproducing the problem.
You've pointed on a bug. I'll fix it soon, but here is a workaround: replace
$TBS->MergeBlock('mb','array','ByTeacher');
with
$TBS->MergeBlock('mb',$ByTeacher);
By: wspras
Date: 2011-02-23
Time: 16:44

Re: Warning Scalar Value in MergeBlock with event function

Thanks for solution,

I am using Automatic subbloks now.
Cause of u & TBS my programs implemented more efficient

regard.

wspras.