Categories > OpenTBS general >

Accessing an array that is not a global variable

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: David
Date: 2012-06-03
Time: 22:12

Accessing an array that is not a global variable

I have an array that contains a value which I can access if I use the following code as a test:
include_once('tbs_class.php');
include_once('tbs_plugin_opentbs.php');

$company_valuation['number_of_years']=1 ;
$TBS = new clsTinyButStrong;
$TBS->Plugin(TBS_INSTALL, OPENTBS_PLUGIN);
$TBS->LoadTemplate(SMARTY_PRIVATE_DIR.'templates/test.docx');
$TBS->Show(OPENTBS_DOWNLOAD, $file_name);
but using the same template when accessed from a included php class give me an error
TinyButStrong Error in field [onshow.company_valuation.number_of_years...]: the key 'company_valuation' does not exist or is not set in VarRef. (VarRef seems refers to $GLOBALS) This message can be cancelled using parameter 'noerr'.

TinyButStrong Error Show() Method: The output is cancelled by the OpenTBS plugin because at least one error has occured.

even though I have tried to use MergeBlock to make the $company_valuation array available.
                include_once('tbs_class.php');
                include_once('tbs_plugin_opentbs.php');

                $TBS = new clsTinyButStrong;
                $TBS->Plugin(TBS_INSTALL, OPENTBS_PLUGIN);

                $TBS->MergeBlock('company_valuation',array($company_valuation));
                // $TBS->LoadTemplate(SMARTY_PRIVATE_DIR.'templates/'.'wordvaltemplate.docx');
                $TBS->LoadTemplate(SMARTY_PRIVATE_DIR.'templates/'.'test.docx');

                $TBS->Show(OPENTBS_DOWNLOAD, $file_name);

The template looks like this:
Date [onshow..now;frm='yyyy-mm-dd']

If the date works we know OPENTBS is working

onshow [onshow. company_valuation.number_of_years]

I have also tried different syntax for the MegeBlock line:
                $TBS->MergeBlock('company_valuation',$company_valuation);
and
                $TBS->MergeBlock('company_valuation','array',$company_valuation);
Any help for a new TBS user is appreciated.
Thanks,
David
By: David
Date: 2012-06-04
Time: 00:15

Re: Accessing an array that is not a global variable

I think I solved my own problem. This seems to work:
                $TBS->VarRef['company_valuation'] = $company_valuation;
//              $TBS->MergeBlock('company_valuation',$company_valuation);
                // $TBS->LoadTemplate(SMARTY_PRIVATE_DIR.'templates/'.'wordvaltemplate.docx');
                $TBS->LoadTemplate(SMARTY_PRIVATE_DIR.'templates/'.'test.docx');

                $TBS->Show(OPENTBS_DOWNLOAD, $file_name);
By: Skrol29
Date: 2012-06-04
Time: 00:46

Re: Accessing an array that is not a global variable

Hi David,

Probably $company_valuation was not a global variable, but only a variable local to a function.