Store value in session and retrieve tpl xcart file

I ran into a problem in x-cart, I'm trying to create a session and save the value in x-cart for this I used

x_session_register('subscription');

and a simple variable in it

$rs=1;
if($rs==1)
{
  $subscription=1;
}
else
{
  $subscription=0;
}

after that I used some code in the tpl file, for example,

{$smarty.session.subscription}

but nothing happens i also tried

{php}{/php}
$_SESSION[''];

but I can’t help me, I can’t understand what is happening with this; there is another file and template, also the path to the file is different try creating a session in login.php and want it in head.tpl please help me with this. thanks in advance

+4
source share
4 answers

Below are some notes related to the session variable related to the x4.doc 4.4.x branch.

x_session_register() ​​ $XCART_SESSION_VARS , , x_session_save(), .

xcart xcart_session_data, ( "sessid" ) "".

:

if ($some_var == "Y"){
  x_session_register("my_var");  
  $my_var="true";
  x_session_save();
}

if($XCART_SESSION_VARS['my_var '] =="true")
  $smarty->assign("my_var", $my_var); 

$XCART_SESSION_VARS , .

+2

php

    if ($var1){
      x_session_register("my_var");  
      $my_var="content";
      x_session_save();
    }

    if($XCART_SESSION_VARS['my_var'] !=""){
      $smarty->assign("my_var", $XCART_SESSION_VARS['my_var']);
      x_session_unregister("my_var"); 
    }

tpl,

{if $my_var}
    {$my_var}
{/if}
+1
// Try this in you php 
$smarty->assign('session',$_SESSION);

// OR in tpl
/*
{$session|print_r} // for above assignment

// OR
{php}
    print_r($_SESSION);
{/php}

// OR
{$smarty.session.*}

*/
0

, - $_SESSION. PHP ( Smarty) var_dump($_SESSION), , -

, , x-cart , ( $_SESSION ). $_SESSION, . http://kb.x-cart.com/display/XDD/Sessions+management

$_SESSION, $_SESSION Smarty, . x-cart , Smarty

0

Source: https://habr.com/ru/post/1540471/


All Articles