Welcome Guest, Not a member yet? Register   Sign In
Cannot access class variables
#1

[eluser]chuckl[/eluser]
I have been trying to figure this out for days and now believe this might be a bug in CI. I am using CI 2.0 with PHP 5.3.2 on Apache 2.2.14 and MySQL 5.1.48-community. I created the following controller:

Code:
class Test extends CI_Controller
{
  public $data = array();

  function __construct();
  {
    parent::_construct();
  }

  function index()
  {
    $this->data['index'] = 'The data[index] element<br />';    
    echo 'Class index() called.<br />';
    echo $this->data['index'];    
  }
    
  function test1()
  {
    $this->data['test1'] = 'The data[test1] element<br />';    
    echo 'Class test1 called.<br />';
    echo $this->data['index'];    
    echo $this->data['test1'];    
  }
    
  function test2()
  {
    echo 'The data array contains these two entries:<br />';
    echo $this->data['index'];    
    echo $this->data['test1'];    
  }
}

$test = new Test;
echo '---------------- index  ----------------------<br />';
echo $test->index();
echo '---------------- test 1 ----------------------<br />';
echo $test->test1();
echo '---------------- test 2 ----------------------<br />';
echo $test->test2();
/* End of file test.php*/
/* Location: */
Using the URL "../index.php/test" produces the following results:
Code:
---------------- index ----------------------
Class index() called.
The data[index] element
---------------- test 1 ----------------------
Class test1 called.
The data[index] element
The data[test1] element
---------------- test 2 ----------------------
The data array contains these two entries:
The data[index] element
The data[test1] element
Class index() called.
The data[index] element
The URL "../index.php/test/test1" produces the following results:
Code:
---------------- index ----------------------
Class index() called.
The data[index] element
---------------- test 1 ----------------------
Class test1 called.
The data[index] element
The data[test1] element
---------------- test 2 ----------------------
The data array contains these two entries:
The data[index] element
The data[test1] element
Class test1 called.
_________________________________
A PHP Error was encountered

Severity: Notice

Message: Undefined index: index

Filename: controllers/test.php

Line Number: 24
__________________________________
The data[test1] element
The URL "../index.php/test/test2" produces the following results:
Code:
---------------- index ----------------------
Class index() called.
The data[index] element
---------------- test 1 ----------------------
Class test1 called.
The data[index] element
The data[test1] element
---------------- test 2 ----------------------
The data array contains these two entries:
The data[index] element
The data[test1] element
The data array contains these two entries:
_________________________________
A PHP Error was encountered

Severity: Notice

Message: Undefined index: index

Filename: controllers/test.php

Line Number: 31
_________________________________
A PHP Error was encountered

Severity: Notice

Message: Undefined index: test1

Filename: controllers/test.php

Line Number: 32
_________________________________
Could this be caused by the CI instantiation of the controller class? It's almost as though the controller gets freshly instantiated with every method call.


Messages In This Thread
Cannot access class variables - by El Forum - 04-01-2011, 02:42 PM
Cannot access class variables - by El Forum - 04-01-2011, 04:42 PM
Cannot access class variables - by El Forum - 04-01-2011, 05:50 PM
Cannot access class variables - by El Forum - 04-01-2011, 06:22 PM
Cannot access class variables - by El Forum - 04-02-2011, 04:05 PM
Cannot access class variables - by El Forum - 04-02-2011, 05:54 PM
Cannot access class variables - by El Forum - 04-03-2011, 12:22 AM
Cannot access class variables - by El Forum - 04-03-2011, 01:08 AM
Cannot access class variables - by El Forum - 04-03-2011, 01:10 AM
Cannot access class variables - by El Forum - 04-03-2011, 01:34 AM
Cannot access class variables - by El Forum - 04-03-2011, 04:08 AM
Cannot access class variables - by El Forum - 04-03-2011, 06:28 AM



Theme © iAndrew 2016 - Forum software by © MyBB