Search

Hi there,

I’m having trouble getting data from a session into a custom datasource. This is the datasource code I use:

<?php

session_start(); 

require_once(TOOLKIT . '/class.datasource.php');

Class datasourceSession_Data extends Datasource{

    public $dsParamROOTELEMENT = 'session-data';

    public function about(){
        return array(
                 'name' => 'Session Data',
                 'author' => array(
                        'name' => 'Your Name',
                        'email' => 'you@yourdomain.com'),
                );
    }

    public function getSource(){
        return '1';
    }

    public function grab(&$param_pool){


        $result = new XMLElement($this->dsParamROOTELEMENT);
$result->appendChild(new XMLElement('test', 'test'));
        $result->appendChild(new XMLElement('count', count($_SESSION['cart']['items'])));

        foreach($_SESSION['cart']['items'] as $key=>$value) {
            $result->appendChild(new XMLElement('item', 'item'));
        }

        return $result;
    }
}

I’m gussing this should work, but somehow nothing of the session data shows up in the XML (the session itself is working fine). Am I doing somehting wrong, is there some sort of session conflict?

I’m really lost here, if someone could post a really basic example of how to get the session data into the custom datasource I would be on my way :)

You might take a look at the Session Monster extension and see how it is done there!

Thanks micheal,

I’m doing almost the exact same thing, but it doesn’t work. the only thing different is dat the extension is using a ‘-sessionmonster’ prefix, but I doubt that could be it?

The session itself is ok, it just doesn’t show up in the xml debug..

Didn’t Rowan do this with the Shopping Cart extension?

Ok thanks, I will try that out.

Meanwhile I made a vardump($SESSION);die;, and this is what came out:

array(2) {
  ["sym-"]=>
  &array(2) {
    ["username"]=>
    string(3) "Bob"
    ["pass"]=>
    string(32) ".."
  }
  ["euh"]=>
  string(4) "test"
}

Oddly the cart is not in there, while the cart session is filled?

Might there be some sort of prefix needed for the cart session so it’s not cleared by symphony? I’m seeing ‘SYMCOOKIEPREFIX’ in the session monster extension, but no decleration anywhere.

Ok is has something to do with the cookieprefix it seems. It is defined in the manifest as ‘sym-‘. But if I use that literal as a prefix for the cart sessions (as in $SESSION[‘sym-cart’]) the data still doesn’t show up in the var_dump.

Might it be that the cart session is not filled from within a Symphony event?

Are you populating $_SESSION outside of symphony?

Hi alpacaaa

Yes that’s right.. I’m guessing that would be a problem? Would there be anyway to solve that (I hope)?

Symphony overrides default php session handling with a custom handler. The main difference is that everything is stored in the db.

I think it would be quite difficult to initialize each required symphony component outside of it, I would personally go with $_COOKIE instead (which should work fine).

Ok.. that would mean a significant rewrite of the current shop. I will check out $_COOKIE, thanks.

Would ther be any other way to access the sessions variables populated outside symphony from within a datasource or event?

Well, it turns out it’s actually possible. I didn’t test the code but, from what I understand, something like this might work:

$session = getSessionData(); // use $session instead of $_SESSION now!
var_dump($session['cart']['items']);

Whether it works or not, to me it looks like a very bad practice throwing in two different sessions in the same script.

@bd_creations: I played around with the ol’ Session Monster extension, and it’s still basically working — but only outside of debug mode. In debug mode, the session data will be cleared I experience problems in displaying the session data. (Don’t ask me why.) Might this be your problem?

Another idea: Maybe your grab function needs session_start(); to let PHP knows which session data to return? At least that’s the way it is done in the Session Monster extension.

Thanks a lot, I will check it out and report what works!

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details