By: James
Date: 2006-12-13
Time: 16:43
|
Nested Arrays
Okay,
So this might be another question worthy of the 'RTFM' response but I've had a look through and either overlooked or have not found what I need. Basically what I have is a large nested array.
It looks like this:
[1] => Array
(
[name] => Rabbits
[children] => Array
(
[0] => Array
(
[0] => 55
[1] => Turbo Rabbits
)
[1] => Array
(
[0] => 56
[1] => More Rabbits
)
)
)
|
Is there a way I can have certain areas of a template read only the first layer in the nested array and other areas access both layers ?
Thanks,
James
|
By: RwD
Date: 2006-12-14
Time: 00:35
|
Re: Nested Arrays
actually, I don't really know if tbs can do this without tricks.
I was looking through the forum because I am pretty sure I dod something like this ones already...
You could first merge the first layer of the array and while doing this create new tbs tags which you will merge later. I'll give a small example which might have mistakes. But you'll figure it out...
template: <div>
<h1>[animals.name; block=div]</h1>
<div class="children">
<h2>[children[animals.id].0;block=div]</h2>
<p>nr: [children[animals.id].1]</p>
</div>
</div> |
For this to work you need two things:
- An extra field named id in the first level of the array
- Merge the first level first. Then using php traverse the array and merge each 'children' array you find with the tbs block "children + id".
The way this works is that you are creating new tbs blocks on the fly. These new blocks get a unique number which you use in the second php round of merging...
I am really certain I've used this trick at least once quite a while ago. Good luck
ps, I surely hope tbs didn't become capable of processing subarrays since that time I used this trick :P otherwise my explanation becomes a bit silly ;)
|
By: Skrol29
Date: 2006-12-14
Time: 01:41
|
Re: Nested Arrays
Hi,
The first level can be merged using a normal MergeBlock().
The second level can be merged using subblocks and an Array "query". This type of query is supported by TBS.
Example:
$TBS->MergeBlock('main',$data);
$TBS->MergeBlock('sub','data[%p1%][children]'); // $data must be a global variable
|
HTML :
<div>
<b> [main.name;block=div] </b>
<div> id=[sub.0;block=div;p1=[main.$]] , label=[sub.1] </div>
</div>
|
|
By: RwD
Date: 2006-12-14
Time: 10:57
|
Re: Nested Arrays
So basically TBS can ue the array as if it was a query resultset?
But what to do if I had this problem? I only declare one global variable in my entire system. This global contains all info of all objects and other variables. So in my case $data would most definately not be a global.
|
By: Skrol29
Date: 2006-12-14
Time: 12:30
|
Re: Nested Arrays
I made a mistake, the PHP should be:
$TBS->MergeBlock('main',$data);
$TBS->MergeBlock('sub','array','data[%p1%][children]'); // $data must be a global variable
|
> But what to do if I had this problem? I only declare one global variable
> in my entire system. This global contains all info of all objects and other
> variables. So in my case $data would most definately not be a global.
I'm afraid I don't understand your question.
|
By: RwD
Date: 2006-12-17
Time: 17:49
|
Re: Nested Arrays
All of my variables are contained within one big global variable. This is needed for integration into other systems. So you say that $data must be a global variable. But I won't have data as a real global. In my case it will allways be a local variable unless the variable is part of an object. How do I use your trick?
Would I be able to use the following variable "somevariablesArray" which I can access in php like this (If I would to be using the global var directly. Normally I would use member functions to get that variable)
$mySystemVar->sessionObject->somevariablesArray
I hope this actually helped in making more clearly what my question is...
|
By: Skrol29
Date: 2006-12-18
Time: 00:33
|
Re: Nested Arrays
$GLOBALS['rwd'] =& $mySystemVar->sessionObject->somevariablesArray;
...
$TBS->MergeBlock('sub','rwd[%p1%][children]');
|
or
global $rwd;
$rwd =& $mySystemVar->sessionObject->somevariablesArray;
...
$TBS->MergeBlock('sub','rwd[%p1%][children]');
|
or if $mySystemVar is global, I think this is supported by TBS :
global $rwd;
$TBS->MergeBlock('sub','mySystemVar->sessionObject->somevariablesArray[%p1%][children]');
|
|
|
Posting in progress.
Please wait...
|