XMF Session Helper

This example simply toggles a session value each time it is run.

Reload the page to toggle the value.


Toggling session variable.

Session variable not set. Setting as: 2019-11-22 00:51:49
string(19) "2019-11-22 00:51:49"
array(2)
'xos_opal_ThemeFactory' => array(1)
'defaultTheme' => string(7) "xswatch"
'xmfdemo_widget' => string(27) "s:19:"2019-11-22 00:51:49";"
Xmf\Module\Helper\Session(3)
  • contents
  • Available methods (9)
  • protected prefix -> string(8) "xmfdemo_"
    protected module -> XoopsModule(9)
    • contents
    • Available methods (71)
    • public modinfo -> NULL
      public adminmenu -> NULL
      public _msg -> NULL
      public vars -> array(13)
       valuerequireddata_typemaxlengthchangedoptionsenumeration
      "mid""15"FALSE3NULLFALSE""""
      "name""Xmfdemo"TRUE1150FALSE""""
      "version""100"FALSE3NULLFALSE""""
      "last_update"
      string(10) "1494707267"
      • timestamp
      • 2017-05-13 22:27:47
      FALSE3NULLFALSE""""
      "weight""1"FALSE3NULLFALSE""""
      "isactive""1"FALSE3NULLFALSE""""
      "dirname""xmfdemo"TRUE7NULLFALSE""""
      "hasmain""1"FALSE3NULLFALSE""""
      "hasadmin""1"FALSE3NULLFALSE""""
      "hassearch""0"FALSE3NULLFALSE""""
      "hasconfig""1"FALSE3NULLFALSE""""
      "hascomments""0"FALSE3NULLFALSE""""
      "hasnotification""0"FALSE3NULLFALSE""""
      public cleanVars -> array(0)
      public _isNew -> boolFALSE
      public _isDirty -> boolFALSE
      public _errors -> array(0)
      public _filters -> array(0)
    • public static getByDirname($dirname) -> mixed
      @param $dirname
      
      @return mixed
      
      Defined in <ROOT>/kernel/module.php:437
      public XoopsObject()
      PHP 4 style constructor compatibility shim
      @deprecated all callers should be using parent::__construct()
      
      Inherited from XoopsObject
      Defined in <ROOT>/kernel/object.php:122
      public __clone()
      Adjust a newly cloned object
      
      Inherited from XoopsObject
      Defined in <ROOT>/kernel/object.php:985
      public __construct()
      Constructor
      
      Defined in <ROOT>/kernel/module.php:46
      public _loadFilters()
      load all additional filters that have been registered to the object
      
      @access private
      
      Inherited from XoopsObject
      Defined in <ROOT>/kernel/object.php:900
      public assignVar($key, $value)
      assign a value to a variable
      
      @access public
      @param string $key   name of the variable to assign
      @param mixed  $value value to assign
      
      Inherited from XoopsObject
      Defined in <ROOT>/kernel/object.php:215
      public assignVars($var_arr)
      assign values to multiple variables in a batch
      
      @access   private
      @param $var_arr
      @internal param array $var_array associative array of values to assign
      
      Inherited from XoopsObject
      Defined in <ROOT>/kernel/object.php:268
      public checkAccess()
      Defined in <ROOT>/kernel/module.php:451
      public cleanVars() -> bool true if successful
      clean values of all variables of the object for storage.
      also add slashes wherever needed
      
      YOU SHOULD NOT USE ANY OF THE UNICODE TYPES, THEY WILL BE REMOVED
      
      @return bool true if successful
      @access public
      
      Inherited from XoopsObject
      Defined in <ROOT>/kernel/object.php:703
      public destoryVars($var) -> bool
      @param $var
      @return bool
      @deprecated use destroyVars() instead,  destoryVars() will be removed in the next major release
      
      Inherited from XoopsObject
      Defined in <ROOT>/kernel/object.php:337
      public destroyVars($var) -> bool
      unset variable(s) for the object
      
      @access public
      
      @param mixed $var
      
      @return bool
      
      Inherited from XoopsObject
      Defined in <ROOT>/kernel/object.php:316
      public dirname($format = "") -> mixed
      Returns Class Base Variable dirname
      @param  string $format
      @return mixed
      
      Defined in <ROOT>/kernel/module.php:367
      public executeSQL() -> bool
      @return bool
      
      Defined in <ROOT>/kernel/module.php:526
      public executeScript($type, $state = 2) -> bool
      @param     $type
      @param int $state
      
      @return bool
      
      Defined in <ROOT>/kernel/module.php:602
      public &getAdminMenu() -> string
      Get the admin menu for the module
      
      @return string
      
      Defined in <ROOT>/kernel/module.php:212
      public getCurrentPage() -> bool
      @return bool
      
      Defined in <ROOT>/kernel/module.php:483
      public getErrors() -> array an array of errors
      return the errors for this object as an array
      
      @return array an array of errors
      @access public
      
      Inherited from XoopsObject
      Defined in <ROOT>/kernel/object.php:1013
      public getHtmlErrors() -> string html listing the errors
      return the errors for this object as html
      
      @return string html listing the errors
      @access public
      
      Inherited from XoopsObject
      Defined in <ROOT>/kernel/object.php:1024
      public &getInfo($name = NULL) -> array |string Array of module information.
      Get module info
      
      @param  string $name
      @return array  |string    Array of module information.
      If {@link $name} is set, returns a single module information item as string.
      
      Defined in <ROOT>/kernel/module.php:143
      public getMessages() -> array an array of messages
      return the messages for this object as an array
      
      @return array an array of messages
      @access public
      
      Defined in <ROOT>/kernel/module.php:113
      public getValues($keys = NULL, $format = s, $maxDepth = 1) -> array associative array of key->value pairs
      Returns the values of the specified variables
      
      @param  mixed  $keys     An array containing the names of the keys to retrieve, or null to get all of them
      @param  string $format   Format to use (see getVar)
      @param  int    $maxDepth Maximum level of recursion to use if some vars are objects themselves
      @return array  associative array of key->value pairs
      
      Inherited from XoopsObject
      Defined in <ROOT>/kernel/object.php:385
      public getVar($key, $format = s) -> mixed formatted value of the variable
      returns a specific variable for the object in a proper format
      
      YOU SHOULD NOT USE ANY OF THE UNICODE TYPES, THEY WILL BE REMOVED
      
      @access public
      @param  string $key    key of the object's variable to be returned
      @param  string $format format to use for the output
      @return mixed  formatted value of the variable
      
      Inherited from XoopsObject
      Defined in <ROOT>/kernel/object.php:416
      public &getVars() -> array associative array of key->value pairs
      returns all variables for the object
      
      @access public
      @return array associative array of key->value pairs
      
      Inherited from XoopsObject
      Defined in <ROOT>/kernel/object.php:372
      public gettemplate($template, $block = false) -> bool
      @param      $template
      @param bool $block
      
      @return bool
      
      Defined in <ROOT>/kernel/module.php:549
      public hasadmin($format = "") -> mixed
      Returns Class Base Variable hasadmin
      @param  string $format
      @return mixed
      
      Defined in <ROOT>/kernel/module.php:387
      public hascomments($format = "") -> mixed
      Returns Class Base Variable hascomments
      @param  string $format
      @return mixed
      
      Defined in <ROOT>/kernel/module.php:417
      public hasconfig($format = "") -> mixed
      Returns Class Base Variable hasconfig
      @param  string $format
      @return mixed
      
      Defined in <ROOT>/kernel/module.php:407
      public hasmain($format = "") -> mixed
      Returns Class Base Variable hasmain
      @param  string $format
      @return mixed
      
      Defined in <ROOT>/kernel/module.php:377
      public hasnotification($format = "") -> mixed
      Returns Class Base Variable hasnotification
      @param  string $format
      @return mixed
      
      Defined in <ROOT>/kernel/module.php:427
      public hassearch($format = "") -> mixed
      Returns Class Base Variable hassearch
      @param  string $format
      @return mixed
      
      Defined in <ROOT>/kernel/module.php:397
      public id($format = N) -> mixed
      Returns Class Base Variable mid
      @param  string $format
      @return mixed
      
      Defined in <ROOT>/kernel/module.php:297
      public initVar($key, $data_type, $value = NULL, $required = false, $maxlength = NULL, $options = "", $enumerations = "") -> void
      initialize variables for the object
      
      YOU SHOULD NOT USE THE $enumeration PARAMETER
      
      @access   public
      
      @param string $key
      @param int    $data_type set to one of XOBJ_DTYPE_XXX constants (set to XOBJ_DTYPE_OTHER if no data type checking nor text sanitizing is required)
      @param null   $value
      @param bool   $required  require html form input?
      @param int    $maxlength for XOBJ_DTYPE_TXTBOX type only
      @param string $options
      @param string $enumerations
      
      @return void
      
      Inherited from XoopsObject
      Defined in <ROOT>/kernel/object.php:196
      public insert() -> bool
      @return bool
      
      Defined in <ROOT>/kernel/module.php:516
      public insertBlocks() -> bool
      @return bool
      
      Defined in <ROOT>/kernel/module.php:559
      public insertConfig() -> bool
      @return bool
      
      Defined in <ROOT>/kernel/module.php:579
      public insertConfigCategories() -> bool
      @return bool
      
      Defined in <ROOT>/kernel/module.php:569
      public insertGroupPermissions($groups, $type) -> bool
      @param $groups
      @param $type
      
      @return bool
      
      Defined in <ROOT>/kernel/module.php:615
      public insertProfileFields() -> bool
      @return bool
      
      Defined in <ROOT>/kernel/module.php:589
      public insertTemplates() -> bool
      @return bool
      
      Defined in <ROOT>/kernel/module.php:536
      public install($admingroups = array(), $accessgroups = array()) -> bool
      @param array $admingroups
      @param array $accessgroups
      
      @return bool
      
      Defined in <ROOT>/kernel/module.php:496
      public isDirty() -> bool
      @return bool
      
      Inherited from XoopsObject
      Defined in <ROOT>/kernel/object.php:174
      public isNew() -> bool
      @return bool
      
      Inherited from XoopsObject
      Defined in <ROOT>/kernel/object.php:148
      public isactive($format = "") -> mixed
      Returns Class Base Variable isactive
      @param  string $format
      @return mixed
      
      Defined in <ROOT>/kernel/module.php:357
      public last_update($format = "") -> mixed
      Returns Class Base Variable last_update
      @param  string $format
      @return mixed
      
      Defined in <ROOT>/kernel/module.php:337
      public loadAdminMenu()
      Load the admin menu for the module
      
      Defined in <ROOT>/kernel/module.php:198
      public loadErrorMessages() -> bool
      @return bool
      
      Defined in <ROOT>/kernel/module.php:473
      public loadFilters($method)
      load all local filters for the object
      
      Filter distribution:
      In each module folder there is a folder "filter" containing filter files with,
      filename: [name_of_target_class][.][function/action_name][.php];
      function name: [dirname][_][name_of_target_class][_][function/action_name];
      parameter: the target object
      
      @param string $method function or action name
      
      @deprecated \XoopsObject::loadFilters is deprecated since XOOPS 2.5.8 and will be removed in the next major release
      
      Inherited from XoopsObject
      Defined in <ROOT>/kernel/object.php:932
      public loadInfo($dirname, $verbose = true) -> bool true if loaded
      Load the module info for this module
      
      @param string $dirname Module directory
      @param bool   $verbose Give an error on fail?
      
      @return bool true if loaded
      
      Defined in <ROOT>/kernel/module.php:229
      public loadInfoAsVar($dirname, $verbose = true)
      Load module info
      
      @param string  $dirname Directory Name
      @param boolean $verbose
      
      Defined in <ROOT>/kernel/module.php:71
      public loadLanguage($type = main) -> bool
      @param string $type
      
      @return bool
      
      Defined in <ROOT>/kernel/module.php:463
      public mainLink() -> string FALSE on fail
      Get a link to the modules main page
      
      @return string FALSE on fail
      
      Defined in <ROOT>/kernel/module.php:165
      public mid($format = "") -> mixed
      Returns Class Base Variable mid
      @param  string $format
      @return mixed
      
      Defined in <ROOT>/kernel/module.php:307
      public name($format = "") -> mixed
      Returns Class Base Variable name
      @param  string $format
      @return mixed
      
      Defined in <ROOT>/kernel/module.php:317
      public registerFilter($filtername)
      dynamically register additional filter for the object
      
      @param string $filtername name of the filter
      
      @deprecated \XoopsObject::registerFilter is deprecated since XOOPS 2.5.8 and will be removed in the next major release
      
      Inherited from XoopsObject
      Defined in <ROOT>/kernel/object.php:888
      public search($term = "", $andor = AND, $limit = 0, $offset = 0, $userid = 0) -> mixed Search result.
      Search contents within a module
      
      @param  string  $term
      @param  string  $andor 'AND' or 'OR'
      @param  integer $limit
      @param  integer $offset
      @param  integer $userid
      @return mixed   Search result.
      
      Defined in <ROOT>/kernel/module.php:269
      public setDirty()
      *#@+
      mark modified objects as dirty
      
      used for modified objects only
      
      @access public
      
      Inherited from XoopsObject
      Defined in <ROOT>/kernel/object.php:161
      public setErrors($err_str)
      add an error
      
      @param $err_str
      @internal param string $value error to add
      @access   public
      
      Inherited from XoopsObject
      Defined in <ROOT>/kernel/object.php:998
      public setFormVars($var_arr = NULL, $pref = xo_, $not_gpc = false)
      Assign values to multiple variables in a batch
      
      Meant for a CGI context:
      - prefixed CGI args are considered save
      - avoids polluting of namespace with CGI args
      
      @access private
      @param array  $var_arr associative array of values to assign
      @param string $pref    prefix (only keys starting with the prefix will be set)
      @param bool   $not_gpc
      
      Inherited from XoopsObject
      Defined in <ROOT>/kernel/object.php:356
      public setInfo($name, $value) -> bool
      Set module info
      
      @param  string $name
      @param  mixed  $value
      @return bool
      */
      
      Defined in <ROOT>/kernel/module.php:125
      public setMessage($str)
      add a message
      
      @param string $str message to add
      @access public
      
      Defined in <ROOT>/kernel/module.php:102
      public setNew()
      *#@+
      used for new/clone objects
      
      @access public
      
      Inherited from XoopsObject
      Defined in <ROOT>/kernel/object.php:135
      public setVar($key, $value, $not_gpc = false)
      assign a value to a variable
      
      @access public
      @param string $key   name of the variable to assign
      @param mixed  $value value to assign
      @param bool   $not_gpc
      
      Inherited from XoopsObject
      Defined in <ROOT>/kernel/object.php:283
      public setVars($var_arr, $not_gpc = false)
      assign values to multiple variables in a batch
      
      @access private
      @param array $var_arr associative array of values to assign
      @param bool  $not_gpc
      
      Inherited from XoopsObject
      Defined in <ROOT>/kernel/object.php:300
      public subLink() -> string
      Get links to the subpages
      
      @return string
      
      Defined in <ROOT>/kernel/module.php:181
      public toArray() -> array
      Returns an array representation of the object
      
      Deprecated, use getValues() directly
      
      @return array
      
      Inherited from XoopsObject
      Defined in <ROOT>/kernel/object.php:1045
      public unsetDirty()
      Inherited from XoopsObject
      Defined in <ROOT>/kernel/object.php:166
      public unsetNew()
      Inherited from XoopsObject
      Defined in <ROOT>/kernel/object.php:140
      public update() -> bool
      @return bool
      
      Defined in <ROOT>/kernel/module.php:506
      public version($format = "") -> mixed
      Returns Class Base Variable version
      @param  string $format
      @return mixed
      
      Defined in <ROOT>/kernel/module.php:327
      public weight($format = "") -> mixed
      Returns Class Base Variable weight
      @param  string $format
      @return mixed
      
      Defined in <ROOT>/kernel/module.php:347
      public xoopsClone() -> object clone
      create a clone(copy) of the current object
      
      @access public
      @return object clone
      
      Inherited from XoopsObject
      Defined in <ROOT>/kernel/object.php:968
    protected debug -> NULL
  • public __construct($dirname = NULL)
    Instantiate a XoopsModule object for the helper to use.
    The module is determined as follows:
    - if null is passed, use the current module
    - if a string is passed, use as dirname to load
    
    @param string|null $dirname dirname
    
    Inherited from Xmf\Module\Helper\AbstractHelper
    Defined in <ROOT>/class/libraries/vendor/xoops/xmf/src/Xmf/Module/Helper/AbstractHelper.php:46
    public addLog($log) -> void
    Add a message to the module log
    
    @param string $log log message
    
    @return void
    
    Inherited from Xmf\Module\Helper\AbstractHelper
    Defined in <ROOT>/class/libraries/vendor/xoops/xmf/src/Xmf/Module/Helper/AbstractHelper.php:100
    public del($name) -> void
    Deletes a named session variable respecting our module prefix
    
    @param string $name name of variable
    
    @return void
    
    Defined in <ROOT>/class/libraries/vendor/xoops/xmf/src/Xmf/Module/Helper/Session.php:98
    public destroy() -> void
    Delete all session variable starting with our module prefix
    
    @return void
    
    Defined in <ROOT>/class/libraries/vendor/xoops/xmf/src/Xmf/Module/Helper/Session.php:110
    public get($name, $default = false) -> mixed $value value of session variable or false if not set
    Fetch a named session variable respecting our module prefix
    
    @param string $name    name of variable
    @param mixed  $default default value to return if config $name is not set
    
    @return mixed  $value value of session variable or false if not set
    
    Defined in <ROOT>/class/libraries/vendor/xoops/xmf/src/Xmf/Module/Helper/Session.php:81
    public init() -> void
    Initialize parent::__construct calls this after verifying module object.
    
    @return void
    
    Defined in <ROOT>/class/libraries/vendor/xoops/xmf/src/Xmf/Module/Helper/Session.php:40
    public set($name, $value) -> void
    Sets a named session variable respecting our module prefix
    
    @param string $name  name of variable
    @param mixed  $value value of variable
    
    @return void
    
    Defined in <ROOT>/class/libraries/vendor/xoops/xmf/src/Xmf/Module/Helper/Session.php:67
    public setDebug($bool = true) -> void
    Set debug option on or off
    
    @param bool $bool true to turn on debug logging, false for off
    
    @return void
    
    Inherited from Xmf\Module\Helper\AbstractHelper
    Defined in <ROOT>/class/libraries/vendor/xoops/xmf/src/Xmf/Module/Helper/AbstractHelper.php:88
    protected prefix($name) -> string module prefixed name
    Add our module prefix to a name
    
    @param string $name name to prefix
    
    @return string module prefixed name
    
    Defined in <ROOT>/class/libraries/vendor/xoops/xmf/src/Xmf/Module/Helper/Session.php:52

Code


<?php

use Xmf\Debug;
use 
Xmf\Module\Helper;
use 
Xmf\Module\Helper\Session;



echo 
'<h3>' _MA_XMFDEMO_SESSION_VAR_TOGGLE '</h3>';
// toggle a session variable
$varName 'widget';
$sessionHelper = new Session();

$var $sessionHelper->get($varName);
if (
$var) {
    echo 
sprintf(_MA_XMFDEMO_SESSION_VAR_GET$var) . '<br />';
    
$sessionHelper->del($varName);
} else {
    
$var date('Y-m-d H:i:s');
    echo 
sprintf(_MA_XMFDEMO_SESSION_VAR_SET$var) . '<br />';
    
$sessionHelper->set($varName$var);
}

Debug::dump($sessionHelper->get($varName'(not set)'));

Debug::dump($_SESSION$sessionHelper);




Back to the XMF Example List
Design by: XOOPS UI/UX Team