How to pass value from one page to other page?

Hi Everyone,

I have a page which retrieving data from a table. For example: Event page which displays a specific event.

And now I would like to add a url link in this page. If user clicks on it, it takes user to FundEvent page.

FundEvent page contains a form. Using this form I want to collect data and store in a table FUND_EVENT table.

But FUND_EVENT table has event_id field as well. So When user travelling from Event page to FundEvent page, I would like to pass event_id. So that its easy for me to store in FUND_EVENT table.

How can I achieve this?

Could you please suggest me?

Thank you

Hi,

I am storing the data in session variable. Is it fine? Are there any drawbacks if I use it?

Please help me with this.

Thank you,

Srini

I don’t know what is the best practice

but I have met this kind of situation of yours. And usually I would go with Yii’s session

in your event page


Yii::app()->user->setState('event_id', $value);

in the FUND_EVENT table


if(Yii::app()->user->hasState('event_id'))

    $value = Yii::app()->user->event_id;

else

    $value = $defaultValue;

Hi Junxiong,

Its working.

Thank you for your help.

Potential problem:

View webpage with ‘event’ which has id 1

event.id = 1

session[‘event’] = event.id (1)

now click fund_event link

complete the form

fund_event form details submitted

fund_event.event_id (the foreign key) = session[‘event’] (1)

redirect to events page

NOW REPEAT

View page with ‘event’ which has id 2

event.id = 2

session[‘event’] = event.id (2)

now click fund_event link

complete the form

fund_event form details submitted

fund_event.event_id (the foreign key) = session[‘event’] (2)

redirect to events page

NOTHING WRONG UP TO NOW

BUT HIT BROWSER BACK BUTTON (shows fund_event page for event.id=session[‘event’] (which is 2))

HIT BROWSER BACK BUTTON AGAIN (shows event page for event id 2)

STILL OK

BUT HIT BROWSER BACK BUTTON AGAIN (shows events page)

HIT BROWSER BACK BUTTON AGAIN (shows fund_event page for event.id=session[‘event’] (which is STILL 2))

HIT SUBMIT BUTTON

YOU SEE THE ERROR?

YOU JUST SUBMITTED A FORM WITH DATA RELATING TO EVENT WITH ID 1, BUT THE SESSION STILL THINKS THE EVENT ID is 2

THEREFORE, THE fund_event DATA YOU SUBMITTED FOR EVENT WITH ID 2 HAS BEEN SAVED AS EVENT WITH ID 1 FROM PREVIOUS POST DATA

Yikes, I hope that’s understandable lol.