Hide
on 18/8/06

If you use plugins, you may have noticed that your app session data isn't avaialbe in your plugins and vice-versa. There's a good reason for that, as a plugin is intended to be a mini application, self contained etc.

In my case, this was a problem as my plugins are extensions or parts of my application and not seperate. To get around the wandering session data it was necessary to copy the session helper from cake/libs/controllers/components/ to /app/controllers/components and change this line in the constructor method:

  1. <?php
  2. //$this->CakeSession = new
  3. CakeSession($base);
  4. $this->CakeSession = new CakeSession("/");
  5. ?>

.. and in that way my session applies to everything under my app folder.

5 Responses to Sessions and Plugins

  1. 1
    Hi Truster,
    I think I prefer your solution ;)
  2. 2
    you need to set the path in the string,
    ("/myApp/")

    great tip
    Thank's

  3. 3
    It work's fine for me with
    ini_set('session.cookie_path', '/mySubApp/');
    in the plugins app_controllers before filter
  4. 4
    I solved this problem also - in AppController:

    function beforeFilter() {


    if ($this->plugin && is_object($this->Session)) {
    $this->Session->CakeSession->path = '/'; // or whatever You

    want
    }
    }
  5. 5
    ...and ini_set('session.cookie_path', '/') off course ;-)