Invenzzia »

Pages: [1]   Go Down
  Print  
Author Topic: OPTv2: nested sections  (Read 297 times)
Description: data access troubles in array format mode
0 Members and 2 Guests are viewing this topic.
whumble
User

Offline Offline

Posts: 10


View Profile
« on: November 06, 2010, 21:09:48 »

I use array access model (default data format), i.e. two array variables.
Example from the manual:
Code:
$s1 = array(0 =>
    array('item' => 'Foo'),
    array('item' => 'Bar'),
    array('item' => 'Joe'),
);
$s2 = array(0 =>
    // The data for "s2" items that are in the relationship with "Foo".
    array(0 =>
        array('item' => 'A'),
        array('item' => 'B'),
    ),
    // The data for "s2" items that are in the relationship with "Bar".
    array(0 =>
        array('item' => 'C'),
        array('item' => 'D'),
    ),
    // The data for "s2" items that are in the relationship with "Joe".
    array(0 =>
        array('item' => 'E'),
        array('item' => 'F'),
    )
);

Now imagine that I'm allowed to set only one variable for view, say "data".

Code:
$data['s1'] = s1;
$data['s2'] = s2;

$view->data=$data;

In template I use "datasource" attribute to access the outer :

Code:
<opt:section name="s1" datasource="$data.s1">
{$s1.item}  // {$data.s1.item} works as well
<opt:section name="s2">
{$s2.item} // doesn't work
</opt:section>
</opt:section>

how to tell compiler where to take data  from?
"datasource" is breaking relationship,
"parent" as I understand is not applicable in "array access mode",
section name can't be used (as "data.s2") for this purpose either.
The only trick I figured out is to define in template  another variable :

Code:
{$s2 = $data.s2}
<opt:section name="s1" datasource="$data.s1">
{$s1.item}  // {$data.s1.item} works as well
<opt:section name="s2">
{$s2.item} // now it works
</opt:section>
</opt:section>

So the question is what is the optimal way out in my situation.
I don't have access to class where assignment $view->data = $myClass->data() is performed.
I only can produce associative data array and spit it out from my class in data() function.


Logged
Zyx
Your programmer
Administrator
User
*****
Offline Offline

Posts: 291



View Profile WWW
« Reply #1 on: November 07, 2010, 08:19:25 »

Using datasources for nested sections invalidates the automatic relationship building, because these two approaches are in conflict. Unfortunately, if you have to use it, there is currently no good solution for it due to the system architecture and the lack of automatic data format recognition.

If you do not want to use the trick, you can always switch to SingleArray data format which does not have such a limitation.
Logged

PozDrX, Zyx
---Invenzzia group---
Pages: [1]   Go Up
  Print  
 
Jump to:  

Subject Started by Replies Views Last post
OPTv2: Zagnieżdżone sekcje Villentre 4 560 Last post December 20, 2009, 19:56:01
by Zyx
OPF: Open Power Forms - ideas and suggestions Zyx 6 2307 Last post September 09, 2009, 10:51:56
by Zyx
OPTv2: Gdzie mam błąd? - Sekcje hash 8 2032 Last post June 08, 2008, 05:34:47
by hash
OPTv2: Problem z zapytaniem w pętli.. GyniO 6 583 Last post March 15, 2010, 19:26:53
by GyniO
OPTv2: Conditional whitespace duclet 4 1084 Last post November 30, 2009, 20:05:06
by duclet