Welcome Guest, Not a member yet? Register   Sign In
How to start session globally?
#12

(09-21-2018, 06:16 AM)kilishan Wrote: My suggestion: don't worry about loading the session globally. First - that means that if the session isn't needed it isn't loaded which can be good for performance and some security things, IIRC. Second - whenever you first call the service, or use the the service() helper method, the session will be automatically initialized and ready for use.

Code:
// These all ensure session is initialized:
$session = \Config\Services::Session();
session('key');
session()->get('key');
session()->set('key', $value);



211/5000
In CI3 the session was held globally.
I have started the session in BaseController and assigned the values to the respective one from one controller, but when evaluating it in another controller the values do not exist.

PHP Code:
//BaseController
$this->sesion  = \Config\Services::session(); 

Controller where I assign the values to the logged in user session:

PHP Code:
$datosEnSesion = array(
 
'usuario'=>$usuarioEncontrado->usuario,
 
'usuario_nombre'=>$usuarioEncontrado->usuario_nombre,
 
'usuario_estado'=>$usuarioEncontrado->usuario_estado,
 
'chequear'=>true,
 
'MenuUsuarioLogueado'=>$MenuUsuarioLogueado,
 
'ids_modulo_opciones'=>$ids_modulo_opciones
 
);
 
//agrego los datos a una sesion
$this->sesion->set($datosEnSesion); 


If I print those values on the current controller, it works correctly, but when evaluating them on another controller, it no longer exists.
Other controller:

PHP Code:
public function __construct(){
 
//parent::__construct();
 //establezco la zona horario par El Salvador
 
date_default_timezone_set('America/El_Salvador');
 
//comprobamos si el usuario está logueado
 
 
$this->sesion session();
 if(
$this->sesion->chequear != true)
 {
 
//si no estoy logueado que me envie a index
 
return redirect()->to(base_url());
 }
 
 
 } 

Any idea why that happens?
Reply


Messages In This Thread
How to start session globally? - by happyape - 09-21-2018, 04:35 AM
RE: How to start session globally? - by sv3tli0 - 09-21-2018, 04:59 AM
RE: How to start session globally? - by happyape - 09-21-2018, 05:21 AM
RE: How to start session globally? - by happyape - 09-21-2018, 05:34 AM
RE: How to start session globally? - by sv3tli0 - 09-21-2018, 06:10 AM
RE: How to start session globally? - by happyape - 09-21-2018, 06:16 AM
RE: How to start session globally? - by kilishan - 09-21-2018, 06:16 AM
RE: How to start session globally? - by happyape - 09-21-2018, 06:58 AM
RE: How to start session globally? - by happyape - 09-21-2018, 07:36 AM
RE: How to start session globally? - by macruzgi - 11-04-2019, 10:48 AM
RE: How to start session globally? - by macruzgi - 11-04-2019, 01:21 PM
RE: How to start session globally? - by kilishan - 09-21-2018, 09:21 AM
RE: How to start session globally? - by macruzgi - 11-04-2019, 01:29 PM
RE: How to start session globally? - by macruzgi - 11-04-2019, 03:05 PM
RE: How to start session globally? - by macruzgi - 11-05-2019, 07:51 AM
RE: How to start session globally? - by macruzgi - 11-08-2019, 04:17 PM
RE: How to start session globally? - by InsiteFX - 11-05-2019, 05:50 PM



Theme © iAndrew 2016 - Forum software by © MyBB