|
169 | 169 | border: 1px dotted #6699CC;
|
170 | 170 | }
|
171 | 171 | .note {
|
172 |
| - background-color: #D9FFD9; |
| 172 | + background-color: #D9FFD9; /* green */ |
173 | 173 | border: thin solid #00EC9F;
|
174 | 174 | padding: 2px;
|
175 | 175 | margin-top: 3px;
|
176 | 176 | margin-left: 20px;
|
177 | 177 | }
|
| 178 | +.warning { |
| 179 | + background-color: #f4dfdf; /* light red */ |
| 180 | +} |
178 | 181 | -->
|
179 | 182 | </style>
|
180 | 183 | </head>
|
|
188 | 191 | </tr>
|
189 | 192 | <tr>
|
190 | 193 | <td>Date:</td>
|
191 |
| - <td>2021-08-27</td> |
| 194 | + <td>2022-02-07</td> |
192 | 195 | </tr>
|
193 | 196 | </table>
|
194 | 197 | </div>
|
195 | 198 | <div style="margin:auto; width:500px; text-align:center;">
|
196 | 199 | <h1>TinyButStrong Documentation</h1>
|
197 |
| - <div class="txt-tiny">version 3.12</div> |
| 200 | + <div class="txt-tiny">version 3.13</div> |
198 | 201 | <div style="margin-top:10px;">Template Engine for Pro and Beginners<br>
|
199 | 202 | PHP 8<br>
|
200 | 203 | PHP 7<br>
|
@@ -270,7 +273,19 @@ <h2>Table of Contents:</h2>
|
270 | 273 | </tr>
|
271 | 274 | <tr>
|
272 | 275 | <td> <a href="#php_getoption"><span class="txt-small">method</span> GetOption()</a></td>
|
273 |
| - <td>get TBS options</td> |
| 276 | + <td>get TBS options</td> |
| 277 | + </tr> |
| 278 | + <tr> |
| 279 | + <td> <a href="#php_resetvarref"><span class="txt-small">method</span> ResetVarRef()</a></td> |
| 280 | + <td>reset the VarRef property</td> |
| 281 | + </tr> |
| 282 | + <tr> |
| 283 | + <td> <a href="#php_getvarrefitem"><span class="txt-small">method</span> GetVarRefItem()</a></td> |
| 284 | + <td>get an item in the VarRef property</td> |
| 285 | + </tr> |
| 286 | + <tr> |
| 287 | + <td> <a href="#php_setvarrefitem"><span class="txt-small">method</span> SetVarRefItem()</a></td> |
| 288 | + <td>set an item in the VarRef property</td> |
274 | 289 | </tr>
|
275 | 290 | <tr>
|
276 | 291 | <td> <a href="#php_replacefields"><span class="txt-small">method</span> ReplaceFields()</a></td>
|
@@ -1322,6 +1337,45 @@ <h3><a id="php_getoption"></a>Method GetOption():</h3>
|
1322 | 1337 | <p class="versioning">Versioning: methods GetOption() is supported since TBS version 3.8.0. </p>
|
1323 | 1338 | </div>
|
1324 | 1339 |
|
| 1340 | + <h3><a id="php_resetvarref"></a>Method ResetVarRef():</h3> |
| 1341 | + <div class="norm"> |
| 1342 | + <p>Reset the <a href="#php_varref" class="opt-name">VarRef</a> property.</p> |
| 1343 | + <p>By default, VarRef refers to the <a href="https://www.php.net/manual/en/reserved.variables.globals.php">PHP global variable $GLOBALS</a>.</p> |
| 1344 | + <p> Syntax: <span class="txt-code"><span class="opt-type">mixed</span> <span class="opt-name">$TBS</span>->ResetVarRef(<span class="opt-type"><span class="opt-value">boolean</span></span> <span class="opt-name">$to_globals</span>)</span></p> |
| 1345 | + <table border="0" cellpadding="5" cellspacing="0"> |
| 1346 | + <tr> |
| 1347 | + <th>Argument</th> |
| 1348 | + <th>Description</th> |
| 1349 | + </tr> |
| 1350 | + <tr> |
| 1351 | + <td align="left" valign="top" class="opt-name"><span class="txt-code">$to_globals</span></td> |
| 1352 | + <td align="left" valign="top">Indicates if the property VarRef refers to $GLOBALS or is a new empty array. |
| 1353 | + <br>- if <span class="opt-name">$to_globals</span> is <span class="txt-code"><span class="opt-type">true</span></span> then VarRef refers to $GLOBALS. |
| 1354 | + <br>- if <span class="opt-name">$to_globals</span> is <span class="txt-code"><span class="opt-type">false</span></span> then VarRef is a new empty array.</td> |
| 1355 | + </tr> |
| 1356 | + </table> |
| 1357 | + </div> |
| 1358 | + |
| 1359 | + <h3><a id="php_getvarrefitem"></a>Method GetVarRefItem():</h3> |
| 1360 | + <div class="norm"> |
| 1361 | + <p>Get an item value in the <a href="#php_varref" class="opt-name">VarRef</a> property.</p> |
| 1362 | + <p>This function uniformizes the way to get a <a href="#php_varref" class="opt-name">VarRef</a> item, whether VarRef refers to <a href="https://www.php.net/manual/en/reserved.variables.globals.php">$GLOBALS</a> or not.</p> |
| 1363 | + <p> Syntax: <span class="txt-code"><span class="opt-type">mixed</span> <span class="opt-name">$TBS</span>->GetVarRefItem(<span class="opt-type"><span class="opt-value">string</span></span> <span class="opt-name">$key</span>, <span class="opt-type"><span class="opt-value">mixed</span></span> <span class="opt-name">$default</span> = <span class="opt-value">null</span>)</span></p> |
| 1364 | + <p>If VarRef if a dedicated array, then this function is the same as doing <span class="txt-code">$TBS->VarRef[$key] ?? $default;</span></p> |
| 1365 | + <p class="versioning">Versioning: methods GetVarRefItem() is supported since TBS version 3.13.0.</p> |
| 1366 | + </div> |
| 1367 | + |
| 1368 | + <h3><a id="php_setvarrefitem"></a>Method SetVarRefItem():</h3> |
| 1369 | + <div class="norm"> |
| 1370 | + <p>Set an item value in the <a href="#php_varref" class="opt-name">VarRef</a> property.</p> |
| 1371 | + <p>This function uniformizes the way to set a <a href="#php_varref" class="opt-name">VarRef</a> item, whether VarRef refers to <a href="https://www.php.net/manual/en/reserved.variables.globals.php">$GLOBALS</a> or not.</p> |
| 1372 | + <p> Syntax: <span class="txt-code"><span class="opt-type">mixed</span> <span class="opt-name">$TBS</span>->SetVarRefItem(<span class="opt-type"><span class="opt-value">string</span></span> <span class="opt-name">$key</span>, <span class="opt-type"><span class="opt-value">mixed</span></span> <span class="opt-name">$value</span>)</span></p> |
| 1373 | + <p>If VarRef if a dedicated array, then this function is the same as doing <span class="txt-code">$TBS->VarRef[$key] = $value;</span></p> |
| 1374 | + <p class="versioning">Versioning: methods SetVarRefItem() is supported since TBS version 3.13.0.</p> |
| 1375 | + </div> |
| 1376 | + |
| 1377 | + |
| 1378 | + |
1325 | 1379 | <h3><a id="php_replacefields"></a>Method ReplaceFields():</h3>
|
1326 | 1380 | <div class="norm">
|
1327 | 1381 | <p>Replace a set of simple TBS fields in the template with new definitions prepared at the PHP side. Note than this function does not merges any field ; it only replaces the definition of fields.</p>
|
@@ -1388,7 +1442,7 @@ <h3><a id="php_getattvalue"></a>Method GetAttValue():</h3>
|
1388 | 1442 | <li><span class="txt-code opt-value">null</span> if the TBS field is not found or if it has no parameter <a href="#html_field_prm_all" class="opt-name">att</a>,</li>
|
1389 | 1443 | <li><span class="txt-code opt-value">false</span> if the target XML/HTML element is not found or if the asked attribute is not found.</li>
|
1390 | 1444 | </ul>
|
1391 |
| -<p class="versioning">Versioning: methods GetAttValue() is supported since TBS version 3.11.0. </p> |
| 1445 | + <p class="versioning">Versioning: methods GetAttValue() is supported since TBS version 3.11.0. </p> |
1392 | 1446 | </div>
|
1393 | 1447 |
|
1394 | 1448 | <h3><a id="php_plugin"></a>Method PlugIn():</h3>
|
@@ -1416,29 +1470,56 @@ <h4>Installing a plug-in: </h4>
|
1416 | 1470 | </ul>
|
1417 | 1471 | <p class="versioning">Versioning: the method PlugIn() is supported since TBS version 3.0. </p>
|
1418 | 1472 | </div>
|
| 1473 | + |
1419 | 1474 | <h3><a name="php_varref"></a>Property VarRef:</h3>
|
1420 | 1475 | <div class="norm">
|
1421 |
| - <p>This property enables you to set the scope of variables availables for <a href="#html_field_auto">automatic fields</a> ([onload], [onshow] and [var]).</p> |
1422 |
| - <p>By default, VarRef is a <a href="http://www.php.net/manual/en/language.references.whatare.php">reference</a> to the <span class="opt-name">$GLOBALS</span> PHP variable, which means all global PHP variables are available for automatic field.</p> |
| 1476 | + <p>Property VarRef is the array of the items that will be merged with <a href="#html_field_auto">automatic fields</a> ([onload], [onshow] and [var]).</p> |
1423 | 1477 | <p> Syntax: <span class="txt-code"><span class="opt-type">array</span> <span class="opt-name">$TBS</span>->VarRef</span></p>
|
| 1478 | + <p> |
| 1479 | + By default <span class="txt-code">$TBS->VarRef</span> refers |
| 1480 | + to the special <a class="opt-name" href="https://www.php.net/manual/en/reserved.variables.globals.php">$GLOBALS</a> variable of PHP. |
| 1481 | + This is for compatibility reasons, but it is recommended to use another array instead (see below). |
| 1482 | + </p> |
| 1483 | + <p>You can set <span class="txt-code">$TBS->VarRef</span> to be a new empty array using the method <span class="txt-code">$TBS->ResetVarRef(false);</span></p> |
| 1484 | + <p>You can also set <span class="txt-code">$TBS->VarRef</span> to be a reference to your own array : <span class="txt-code">$TBS->VarRef =& $my_array;</span></p> |
| 1485 | + |
| 1486 | + <div class="decal warning"> |
| 1487 | + <strong>Warning</strong> |
| 1488 | + <br>As of TBS version 3.13.0, is not possible to access directly to the VarRef items when the property refers to $GLOBALS. This is because of the PHP restriction on $GLOBALS that occurs with PHP 8.1. |
| 1489 | + <br>In order to ensure the compatibility to any situation, you can manage the items of VarRef using the methods <a href="#php_setvarrefitem" class="txt-code">$TBS->SetVarRefItem()</a> and <a href="#php_setvarrefitem" class="txt-code">$TBS->GetVarRefItem()</a>. |
| 1490 | + </div> |
| 1491 | + |
1424 | 1492 | <p>Notes:</p>
|
1425 | 1493 | <ul>
|
1426 |
| - <li> Method<span class="txt-code"> ResetVarRef(<span class="opt-name">$ToGlobal</span>)</span> is a shorthand for reseting property VarRef to <span class="opt-name">$GLOBALS</span> or to an empty array.</li> |
| 1494 | + <li> Method <a href="#php_resetvarref" class="txt-code">ResetVarRef(<span class="opt-name">$ToGlobal</span>)</a> is a shorthand for resetting property VarRef to <a class="opt-name" href="https://www.php.net/manual/en/reserved.variables.globals.php">$GLOBALS</a> or to an empty array.</li> |
1427 | 1495 | <li> If property VarRef is changed by a sub-template, the change is available only for the sub-template.</li>
|
1428 | 1496 | </ul>
|
1429 |
| -<p>Example for setting VarRef to global variables :</p> |
1430 |
| -<pre class="decal txt-code"><span class="opt-name">$TBS</span>->VarRef = &<span class="opt-name">$GLOBALS</span>; |
| 1497 | + |
| 1498 | + <p>Example when VarRef is a custom array (recommended): </p> |
| 1499 | + <pre class="decal txt-code"><span class="opt-name">$TBS</span>->ResetVarRef(false); <span class="opt-html">// VarRef is now a new empty array</span> |
| 1500 | +<span class="opt-name">$TBS</span>->VarRef['my_item'] = "my value"; |
| 1501 | +<span class="opt-name">$TBS</span>->SetVarRefItem('my_item', "my value"); <span class="opt-html">// same as above but ensure the compatibility with any situation</span></pre> |
1431 | 1502 |
|
1432 |
| -which is the same as: |
| 1503 | + <p>Example when VarRef is attached to $GLOBALS (by default): </p> |
| 1504 | + <pre class="decal txt-code"><s><span class="opt-name">$TBS</span>->VarRef['my_item'] = "my value";</s> <span class="opt-html">// this will raise an error as of TBS version 3.13.0</span> |
| 1505 | +<span class="opt-name">$GLOBALS</span>['my_item'] = "my value"; |
| 1506 | +<span class="opt-name">$TBS</span>->SetVarRefItem('my_item', "my value"); <span class="opt-html">// same as above but ensure the compatibility with any situation</span></pre> |
| 1507 | + |
| 1508 | + <div class="versioning"> |
| 1509 | + <p>Versioning:</p> |
| 1510 | + <ul class="list-mini"> |
| 1511 | + <li>Property VarRef is supported since TBS version 3.8. Before this version, the scope of automatic fields was PHP global variables.</li> |
| 1512 | + <li> |
| 1513 | + Since TBS version 3.13.0, you cannot directly use the property <span class="txt-code">$TBS->VarRef</span> when it refers to $GLOBAL. This is because of a PHP 8.1 restriction. Use SetVarRefItem() and GetVarRefItem() instead. |
| 1514 | + <br>Before TBS version 3.13.0, property <span class="txt-code">$TBS->VarRef</span> used to be by default a PHP reference the $GLOBAL variable. |
| 1515 | + </li> |
| 1516 | + </div> |
| 1517 | + |
| 1518 | + </div> |
| 1519 | + |
| 1520 | + |
| 1521 | + <h3><a id="php_assigned"></a>Property Assigned:</h3> |
1433 | 1522 |
|
1434 |
| -<span class="opt-name">$TBS</span>->ResetVarRef(true)<span class="opt-name"></span>; |
1435 |
| -</pre> |
1436 |
| -<p>Example for setting VarRef to a custome scope of variables: </p> |
1437 |
| -<pre class="decal txt-code"><span class="opt-name">$TBS</span>->ResetVarRef(false); <span class="opt-html">// VarRef is now a new empty array</span> |
1438 |
| -<span class="opt-name">$TBS</span>->VarRef['x'] = 'This is value X';</pre> |
1439 |
| - <p class="versioning">Versioning: property VarRef is supported since TBS version 3.8. Before this version, the scope of automatic fields was PHP global variables.</p> |
1440 |
| -</div> |
1441 |
| -<h3><a id="php_assigned"></a>Property Assigned:</h3> |
1442 | 1523 | <div class="norm">
|
1443 | 1524 | <p>Enables you to define information for a subsequent merging which can be automatic or manual. </p>
|
1444 | 1525 | <p> Syntax: <span class="txt-code"><span class="opt-type">array</span> <span class="opt-name">$TBS</span>->Assigned</span></p>
|
|
0 commit comments