ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Accessing Session within custom controller

June 04, 2014 8:26pm

Subscribe [1]
  • #1 / Jun 04, 2014 8:26pm

    TheGroove

    1 posts

    I am trying to access some session data inside a custom controller, but can’t seem to get it to work after upgrading to the latest EE version.

    Part of my setup is based on data from this post:

    http://venodesigns.net/2011/05/07/when-expressionengine-defaults-are-not-enough/

    class MY_CUSTOM_CLASS extends CI_Controller {
    
        public function __construct() {
    
            // Call the CI_Controller's Constructor
            parent::__construct();
    
            // Calls the EE & CI initialization
            //$this->core->_initialize_core(); <-- Commented because this generates an error
            $this->EE =& get_instance();
    
            // Load database class + session library
            $this->EE->load->database();
            $this->EE->load->library('session');
    
        }

    Initializing the core

    $this->core->_initialize_core();

    causes this error

    A PHP Error was encountered
    
    Severity: Notice
    
    Message: Undefined property: MY_CUSTOM_CLASS::$core

    and loading the session library

    $this->EE->load->library('session');


    causes these errors

    A PHP Error was encountered
    
    Severity: Notice
    
    Message: Use of undefined constant REQ - assumed 'REQ'
    
    Filename: libraries/Session.php
    
    Line Number: 1396
    
    --
    
    A PHP Error was encountered
    
    Severity: Notice
    
    Message: Use of undefined constant REQ - assumed 'REQ'
    
    Filename: libraries/Session.php
    
    Line Number: 1105
    
    ---
    
    A PHP Error was encountered
    
    Severity: Notice
    
    Message: Undefined property: MY_CUSTOM_CLASS::$extensions
    
    Filename: libraries/Session.php
    
    Line Number: 137

    Any idea what might cause this and how to solve it?

    Thanks!

  • #2 / Jun 05, 2014 3:28am

    TheGroove

    1 posts

    Was able to get it to work by extending EE_Controller instead of CI_Controller:

    class MY_CUSTOM_CLASS extends EE_Controller {
.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases