I want to send my session data from one controller to another.
<?php
abc.php // controller name
class abc extends MY_Controller
{
public function set_new_data()
{
$_SESSION['sample'] = 'testing';
}
}
?>
<?php
xyz.php // another controller name
class xyzextends MY_Controller
{
public function get_data()
{
echo $_SESSION['sample'];
}
}
?>
I am using HMVC pattern in codeigniter. I want to call abc/set_new_data to set session then redirect to xyz/get_data to get data but I am unable to pass data.
Here, You can try the below code.
Set data method:
class Abc extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->library('session');
}
public function set_new_data()
{
$sess_array = array(
'sample' => 'testing'
);
$this->session->set_userdata($sess_array);
}
}
Get data Method:
class Xyz extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->library('session');
}
public function get_data()
{
echo $this->session->userdata('sample');
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.