• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Assigning & reading value to/from class var from 2 different functions

#1
[eluser]stef569[/eluser]
Code:
class Calender extends Controller {
  var $test = 'test';

function show() {
  $this->createEvents();
}

function createEvents() {
  $this->test = '55';
}

function printTest() {
  echo $this->test;
}

function doTest() {
  $this->createEvents();
  $this->printTest();
}
}
// /doTest/ => OK returns 55
// /createEvents/ => i gues it has been set
// /printTest/ => returns test!!!!!!!!!

When I first call show() in the uri and then printTest() it returns 'test', But i did call the function show to set it on '55'. Why is this?

Is the controller class reloaded everytime i refresh the page?

#2
[eluser]Phil Sturgeon[/eluser]
Yes, they dont stay between page-loads unless you use sessions.

#3
[eluser]stef569[/eluser]
ok, I autoloaded the libary sessions.

I closed my browser,

opened localhost(i'm testing with wamp) enetered my functions

but the output didn't change.
I can see the cookie ci_session.

btw I need this because i want to map days in the calender class to eventId in my datebase.

#4
[eluser]Phil Sturgeon[/eluser]
Not what I meant. PHP uses passive classes which mean that on each pageload it forgets whatever was there and is all set again next time. You have to manually read and write any session variables you want to be remembered between pages.

User Guide: Session Library

#5
[eluser]stef569[/eluser]
Thanks thepyromaniac, I was still bussy thinking in java.

I do read the userguides Wink


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.