Forums

How to select data reader from switch

pdforest 05 Mar, 2020
Hi, I need some help switching a data reader using the user code {session: user.id}

I have 2 data readers {fn:read_datos} and {fn:read_datos_todos}

The switch {fn:switch_read} uses {session:user.id} as data provider, the return the result as var is checked and has the following actions:

/^36[0-6]$/:read_datos_todos{fn:read_datos_todos}
/^36[7-9]$/:read_datos{fn:read_datos}
/^37[0-9]$/:read_datos{fn:read_datos}

The problem is in the view {view:datos_list_table} using the data provider {var:switch_read}

Debug:

[switch_read] => Array
(
[finished] => 1
[var] => read_datos
)

The name of the data reader is returned but the view cannot use it.

Thanks in advance!


SWITCH


VIEW

gix.vax 05 Mar, 2020
hi

is there a reason you put the name of read_action after ":" ??
/^36[0-6]$/:read_datos_todos{fn:read_datos_todos}

try
/^36[0-6]$/:{fn:read_datos_todos}
/^36[7-9]$/:{fn:read_datos}
/^37[0-9]$/:{fn:read_datos}
pdforest 05 Mar, 2020
Hi, I put it there in order to be used by the view as the data provider.
If I put {fn:read_datos} in the view it works ok but i need the data provider to be changed matching the user code in the regex.
pdforest 10 Mar, 2020
Pelease, Can someone help me ?

Thanks!
healyhatman 11 Mar, 2020
In the switch just have the {fn:read_...} part

Then in your data provider do {var:read_dataoption1}|{var:read_dataoption2}|{var:read_dataoption3}
Give them the correct names of course
Doing that, it should use whichever read data actually has data.
pdforest 15 Mar, 2020
Thanks gix.vax and healyhatman for your answer.

I put in the switch_read only the read functions:

/^36[0-6]$/:{fn:read_data1}

/^36[7-9]$/:{fn:read_data2}
/^37[0-9]$/:{fn:read_data3}

It works ok at this part but I want to have only 1 view, how do I know wich data reader was chosen?

I tried to implement a switch to the views: switch_view

/^36[0-6]$/:{view:datos_list1}
/^36[7-9]$/:{view:datos_list2}
/^37[0-9]$/:{view:datos_list3}

The view datos_list1 has {var:read_data1} as the data provider
The view datos_list2 has {var:read_data2} as the data provider
The view datos_list3 has {var:read_data3} as the data provider

The event:

{fn:switch_read}
{fn:switch_view}

But I can't make it work!

Do you know another way to do that?
healyhatman 15 Mar, 2020
You can put both things in the one switch
pdforest 18 Mar, 2020
I put both things in the one switch but the list table is not printed







healyhatman 18 Mar, 2020
You have "return the result as var" turned on, which as the description says won't print. Turn it off.
pdforest 20 Mar, 2020
Hi, thank you, turning off "return the result as var" works fine so at this point I can switch between data readers and viewers using a single switch.

But I still need some help because there are links in the view list table referencing to the row item that doesn't work:

Table column view:
Dato.Nombre:{view:dato_view_link}

and

dato_view_link Content:
{var:datos_list_table.row.Dato.Nombre}

dato_view_link Parameter:
dato_aid={var:datos_list_table.row.Dato.aid}

I don't want to have every link duplicated so I put a session var with the chosen view

I have the variable {session:alegria.dataviewer}

The question is how can I dynamically reference to the view item like this?:

dato_aid={var:{session:alegria.dataviewer}.row.Dato.aid}

But the above code doesn't work.
healyhatman 21 Mar, 2020
data_aid={session:alegria.dataviewer.row.Dato.aid}
pdforest 21 Mar, 2020
Sorry healyhatman but it doesn't work.
healyhatman 21 Mar, 2020
Use a {debug:} to see what data you have available
healyhatman 21 Mar, 2020
Why are you using {session:user.id} by the way, instead of just using {user:id} ?

And try just putting both data sources in the link. Like href="{var:source1whatever}{var:source2whatever}" since only one of them will actually have anything in it.

Could also move these things to their own event. So in your switch you could have {event:somethingsomething} and then you can put all your views and read datas in the event.
This topic is locked and no more replies can be posted.