I thought I would be able to get a session variable from within a plugin component with $this->Session->var but it looks like $this->Session is not available. How do I access the session from the main app?
A:
Because the Session is the component you need to include it with:
<?php
class MyComponent extends Object {
// This component uses other components
var $components = array('Session', 'Math');
function doStuff() {
$result = $this->Math->doComplexOperation(1, 2);
$this->Session->write('stuff', $result);
}
}
?>
You should check this from where the sample is taken.
Nik
2010-07-31 20:54:27
From a plugin it looks like you have to do $this->Controller->Session-read() to access a var in the session.
Mark Flint
2010-08-02 18:22:21
True, but you need to have $this->Controller instance passed. i.e. when calling the plugin you need to pass $this->PluginComponent->method($this); and then properly to set as Plugin's parameter. It's too much effort, and that's why I havent suggest it.
Nik
2010-08-02 19:06:46