2

set_flashdata 仅在一次重定向后无法直接工作。

我在这个过程中使用了一个控制器——Profilers 的控制器。它处理成员确认过程,并在重定向上显示登录页面。过程如下:

  1. 本次会议 set_flashdata ('topic', 'newmember')

  2. 重定向('登录')

  3. route ['login'] = 'profilers/signIn'

  4. topic = $本次会议flashdata('topic')

我已经关闭了所有数据库会话配置以进行更清晰的调试,即使会话库在配置中打开,我仍然开始调用它,这似乎也不起作用。

这是我的代码。如您所见,我将路径信息发送到日志文件 path.log:

在控制器 Profilers 中,函数 confirmMember:

public function confirmMember()
  {
    //use_ssl();
    $this->form_validation->set_rules('handle', 'Unique Member Name', 'trim|xss_clean|required|min_length[5]|max_length[30]');
    $this->form_validation->set_rules('confirmation', 'Confirmation Code', 'trim|xss_clean|required|min_length[20]|max_length[20]|alpha_numeric');

    if ($this->form_validation->run() === FALSE) {echo "here";exit;
      $data['handle']=$this->input->post('handle');
      $data['confirmation']=$this->input->post('confirmation');
      $this->load->view('signing/defaults/header',$data);
      $this->load->view('defaults/heading',$data);
      $this->load->view('defaults/banner');
      $this->load->view('defaults/banner_right');
      $this->load->view('member/temp/index',$data);
      $this->load->view('defaults/footer',$data);
    } else {

      $post = $this->input->post(NULL,TRUE);
      $data['member'] = $this->Signing_model->model_confirmMember($post);

  if ($data['member']['confirmed']!==FALSE) {
    /* PATH CHECK */ 
    error_log("member confirmation not false\n",3, LOG_DIR.'path.log');
    unset($post);
    $this->session->sess_destroy();
    $this->session->set_flashdata('topic', 'newmember');
    // $this->session->keep_flashdata('topic');
    redirect('login','refresh');
  } else {
    /* PATH CHECK */ 
    error_log("member confirmation IS FALSE\n",3, LOG_DIR.'path.log');
    $this->load->view('member/temp/index',$data);
  }

我的日志文件显示该路径使用正确的路径并显示“成员确认不是假的”。

我尝试过使用keep_flash 数据(我认为它不会工作,因为没有其他重定向)并关闭。

我也尝试过没有“刷新”的重定向。

在 config/routes.php 中:

<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

$route['join'] = 'profilers/joinUp';
$route['login'] = 'profilers/signIn';
...

登录页面使用 Profilers Controller,登录功能如上图:

public function signIn()
{
  $topic = $this->session->flashdata('topic');
  if (isset($topic)) {
      $message = "topic is set. topic = ".$topic."\n";
      if ($topic!==FALSE) {
              error_log("flash var topic is not false\n", 3, LOG_DIR.'path.log');
      } else {
              error_log("flash var topic is FALSE\n", 3, LOG_DIR.'path.log');
      }
  } else {
      $message = "topic is NOT set\n";
  }
  error_log($message,3,LOG_DIR.'path.log');

  exit;
  ...
  ...
}

日志文件显示主题已设置但为假。

“flash var 主题为 FALSE”

"主题已设置。主题 = "

当然没有设置主题变量,因为它是错误的。

如您所见,我已将获取闪存数据功能移至控制器功能的开头,以绕过可能损坏数据的任何内容。

4

1 回答 1

8

销毁会话后,您可能需要再次启动会话。

在您致电后尝试添加sess_destory()

$this->session->sess_create()

或者,您可以避免破坏会话以及unset()您希望摆脱的值。

于 2013-08-12T04:49:07.737 回答