Forums / Setup & design / Add my own variable in session
Paul Etienney
Wednesday 25 February 2009 3:08:25 am
Hi,
I would like to build a tracker on specific class.
I would like to know all the objects of the "software" class the visitor have seen.
I can't find a way to add my own variable in the session. Do you know a good solution ?
-- Good websites creation -- My site : http://www.pauletienney.com Twitter : http://www.twitter.com/p_etienney
Wednesday 04 March 2009 8:20:28 am
Any idea ?
Piotrek KaraĆ
Wednesday 04 March 2009 9:31:30 pm
Create a temple operator called for example tracksoftware() that would take two parameters: - function name: 'set' or 'get'- $node_id (or $object_id, up to your needs).
The core code for the operator should look something like:
$http = eZHTTPTool::instance(); // if it is not there already $trackSoftwareSessionVariable = 'PaulTrackSoftware'; $operatorValue = false; if( $function == 'get' ) { if( $http->hasSessionVariable( $trackSoftwareSessionVariable ) ) { $operatorValue = $http->sessionVariable( $trackSoftwareSessionVariable ); } } if( $function == 'set' ) { $nodeIDArray = array(); if( $http->hasSessionVariable( $trackSoftwareSessionVariable ) ) { $nodeIDArray = $http->sessionVariable( $trackSoftwareSessionVariable ); } if( !in_array( $nodeID, $nodeIDArray ) ) { $nodeIDArray[] = $nodeID; } $http->setSessionVariable( $trackSoftwareSessionVariable, $nodeIDArray ); $operatorValue = true; }
This may be buggy, but should get you pretty close to where I think you want to get...
-- Company: mediaSELF Sp. z o.o., http://www.mediaself.pl eZ references: http://ez.no/partners/worldwide_partners/mediaself eZ certified developer: http://ez.no/certification/verify/272585 eZ blog: http://ez.ryba.eu