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

class Calender extends Controller {
  var $test = 'test';

function show() {

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

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

function doTest() {
// /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?

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

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.

[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

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.