Codeigniter闪存数据问题 我没有得到会话flashdata值。我检查了会话,闪存数据创建为旧。为什么会发生这种情况,我该如何纠正这个问题。
我的会话:
3:{s:9:"user_data";s:0:"";s:11:"cp";s:5:"l";s:14:"flash:old:fvalue";s:32:"41f66604a0bec1c089d84023d3708d1d";}.
此处闪存数据标记为旧。我在视图中创建了Flash数据,这是我的代码$this->session->set_flashdata('fvalue', '41f66604a0bec1c089d84023d3708d1d');
答案 0 :(得分:1)
添加flashdata:
$this->session->set_flashdata('stack', 'overflow');
您可以使用以下代码在视图中使用:
$this->session->flashdata('stack');
请确保您的网页不应重定向一次。如果您的重定向计数超过一个,则需要使用:
$this->session->keep_flashdata('stack');
答案 1 :(得分:0)
使用Session类,在//controller
<?php
class Upload extends CI_Controller{
public function upload_image(){
$this->upload_model->do_upload(); //execute the upload function
}
}
//model
<?php
class User_model extends CI_Model{
var $original_path;
var $resized_path;
var $thumbs_path;
//initialize the path where you want to save your images
function __construct(){
parent::__construct();
//return the full path of the directory
//make sure these directories have read and write permessions
$this->original_path = realpath(APPPATH.'../uploads/original');
$this->resized_path = realpath(APPPATH.'../uploads/resized');
$this->thumbs_path = realpath(APPPATH.'../uploads/thumbs');
}
function do_upload(){
$this->load->library('image_lib');
$config = array(
'allowed_types' => 'jpg|jpeg|gif|png', //only accept these file types
'max_size' => 2048, //2MB max
'upload_path' => $this->original_path //upload directory
);
$this->load->library('upload', $config);
$image_data = $this->upload->data(); //upload the image
// desired config for the resize() function
$config = array(
'source_image' => $image_data['full_path'], //path to the uploaded image
'new_image' => $this->resized_path, //path to
'maintain_ratio' => true,
'width' => 128,
'height' => 128
);
$this->image_lib->initialize($config);
$this->image_lib->resize();
config/autoload.php
设置Flash数据
$autoload['libraries'] = array('session');
使用将flash数据重定向到方法后
然后在视图中(显示/这将仅在设置 破坏会话$this->session->set_flashdata('item', 'value');//$this->session->set_flashdata('name', 'Rakesh');
redirect('controller/method_name');
时执行)name
<?php
if($this->session->flashdata('name') != '')
{
?>
<div class="success">
<?php $this->session->flashdata('name'); ?>
</div>
<?php
}
?>