tags:

views:

27

answers:

2

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: 

This might help you out: http://book.cakephp.org/view/173/Sessions

Chris
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
From a plugin it looks like you have to do $this->Controller->Session-read() to access a var in the session.
Mark Flint
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