trante
trante

Reputation: 33986

CakePHP Session component error

In my CakePHP application, when I use another controller's class, I get Session read function error.

example.com/app/getList works well
example.com/seconds/parseList works well
But example.com/first/index gives this error:

Fatal error: Call to a member function read() on a non-object in
/example.com/app/Controller/AppController.php on line 468

Line 468 is this: $list=$this->Session->read('myList');

How can I fix this ?

class FirstController extends AppController {
    public function index () {
        $Seconds = new SecondsController();
        $Seconds->parseList();
    }
}

class SecondsController extends AppController {
    public $helpers = array('Html', 'Session');

    public function parseList () {
        $output = $this->getList();
        return output;
    }
}

class AppController extends Controller {
    public $uses = array('App', 'Mydata');
    var $components    = array('Session');
    public $helpers = array('Session','Html','Cache');

    public function getList () {
        $list=$this->Session->read('myList');
        return $list;
    }
}

Edit: I should mention that example.com/app/getList works well. When I run this action independantly it desn't give Session error.

Upvotes: 0

Views: 3552

Answers (2)

dhofstet
dhofstet

Reputation: 9964

You have to call the constructClasses() method after manually creating an instance of your controller:

$Seconds = new SecondsController();
$Seconds->constructClasses();

Upvotes: 4

L. Sanna
L. Sanna

Reputation: 6552

Did you put var $components = array('Session'); in your AppController?

Upvotes: 0

Related Questions