doucheng7234 2013-07-16 13:07
浏览 41

为什么Codeigniter set_flashdata()会插入错误的信息?

Look at this code:

$this->session->set_flashdata('prev_page', $this->uri->uri_string());
echo $this->uri->uri_string();
echo $this->session->flashdata('prev_page');

When visiting mywebsite/index.php/home/

echo $this->uri->uri_string(); prints home

echo $this->session->flashdata('prev_page'); prints home/picktype, a completely different function in the same controller!

The controller functions in question:

class Home extends MY_Controller {

function __construct()
{
    parent::__construct();
}

public function index()
{   
    if($this->input->cookie('disclaimer_seen_token'))
    {
        $this->load->view('home');

    } else {

        redirect('disclaimer'); 
    }

}

public function picktype()
{   
    $this->load->view('picktype');
}

}

Why could this be happening?

  • 写回答

1条回答 默认 最新

  • doujiongqin0687 2013-07-16 13:13
    关注

    Your flashdata has not been updated until you 'redirect' back to another page.

    So your $this->session->flashdata('prev_page') is your LAST page before the redirect.

    The docs specifically state:

    CodeIgniter supports "flashdata", or session data that will only be available for the next server request, and are then automatically cleared

    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度