当重定向到另一个控制器会话时,在codeigniter中不起作用

时间:2017-04-11 07:48:50

标签: php codeigniter

当我注册并希望将控制器重定向到另一个控制器以显示仪表板时,我被困在这里,然后该时间创建的会话不能在重定向的控制器上工作。这是我的示例代码。

我的注册控制器:

class Signup extends CI_Controller {

 public function __construct()
 {
    parent::__construct();
    $this->load->helper('url');
    $this->load->model('admin_model');
    $this->load->library('form_validation');
    $this->load->helper('cookie');
    $this->load->library('session');
    $this->load->library('email');
    $this->load->helper('string');
    $this->load->library('upload');
}

public function index() {
   if(!$_POST) {
        $this->load->view('web_pages/signup/signup');
   } else {
            $insert_data = array(
            'firstName' => $signup_data['firstName'],
            'lastName' => $signup_data['lastName'],
            'email' => $signup_data['email'],
            'password' => $signup_data['password'],
            'phoneNo' => $signup_data['phoneNo'],
            'userType' => $signup_data['userType'],
            'image' => $image,
            'createDate' => date('Y-m-d H:i:s')
            );
            $this->db->insert('users', $insert_data);
            $this->session->set_userdata(array(
                    'user_id'       => $insert_data['email'],
                    'userType'      => $insert_data['userType'],
                    'status'        => TRUE
                ));

            redirect('dashboard'); //another controller.
        }
   }
}

以下是我的信息中心控制器

class Dashboard extends CI_Controller {

public function __construct()
{
    parent::__construct();
    $this->load->helper('url');
    $this->load->model('admin_model');
    $this->load->library('form_validation');
    $this->load->helper('cookie');
    $this->load->library('session');
    $this->load->library('email');
    $this->load->helper('string');
    $this->load->library('upload');
}

public function index() {
   print_r($_SESSION); die;
}

}

仪表板控制器上方不打印任何内容。

请帮帮我。提前谢谢。

2 个答案:

答案 0 :(得分:1)

使用

打印会话中的数据
[0]=>
  array(7) {
    ["booking_name"]=>
    string(39) "EITTE/91/EEIRCE/CORE NETWORK DESIGN/17B"
    ["asset_count"]=>
    string(1) "2"
    ["PDG"]=>
    string(5) "EITTE"
    ["Deployment_Number"]=>
    string(2) "91"
    ["SPoC"]=>
    string(6) "EEIRCE"
    ["Team_Name"]=>
    string(19) "CORE NETWORK DESIGN"
    ["Release"]=>
    string(3) "17B"
  }

使用以下参数检查配置文件

public function index() {
$this->load->library('session');
print_r($this->session->all_userdata());
}

同时检查cookie配置

$config['sess_expiration']  = 8600;
$config['sess_match_useragent'] = FALSE;

$config['cookie_prefix'] = ""; $config['cookie_domain'] = ""; $config['cookie_path'] = "/"; 进行会话

autoload.php

答案 1 :(得分:0)

请参阅此更新的代码段

    if(!$_POST) {
        $this->load->view('web_pages/signup/signup');
   } else {
            $insert_data = array(
            'firstName' => $this->input->post('firstName'),
            'lastName' => $this->input->post('lastName'),
            'email' => $this->input->post('email'),
            'password' => $this->input->post('password'),
            'phoneNo' => $this->input->post('phoneNo'),
            'userType' => $this->input->post('userType'),
            'image' => $image,
            'createDate' => date('Y-m-d H:i:s')
            );
            $this->db->insert('users', $insert_data);
            $this->session->set_userdata(array(
                    'user_id'       => $this->input->post('email'),
                    'userType'      => $this->input->post('userType'),
                    'status'        => TRUE
                ));

            redirect('dashboard'); //another controller.
        }
   }

然后只需访问会话数据

echo $this->session->userdata('firstname');