0

我对 CI 会话有疑问。我初始化了我的会话库:

$autoload[‘libraries’] = array(‘database’, ‘session’) (In config/autoload.php)

这是我的代码:

cycle

$this->load->library(‘image_moo’);
// Upload image and return unique name
  $data = array(
  ‘image’ => $image,
  );

$this->db->insert(‘category_images’, $data);


  if (!$this->session->userdata(‘uploadImages’))
  {
  $this->session->set_userdata(‘uploadImages’, $this->db->insert_id());
  }
  else
  {
  $session = $this->session->userdata(‘uploadImages’);
  $sessionData = $session.’|’.$this->db->insert_id();
  $this->session->set_userdata(“uploadImages”, $sessionData);
  } 

  echo $this->session->userdata(‘uploadImages’); // return 256; corect result - 255|256

  end of cycle

这是使用 jQuery File Upload (blueimp) 上传图像的脚本,我需要将插入数据库图像的 id 设置为会话。

任何人都可以帮忙。谢谢!

4

2 回答 2

1

要使用CI Session,您还需要在以下内容中提供加密密钥application/config.php

$config['encryption_key'] = 'xxxxxx';`
于 2013-09-06T10:56:20.917 回答
0

尝试这个

cycle

    $this->load->library(‘image_moo’);
    // Upload image and return unique name
      $data = array(
      ‘image’ => $image,
      );

    $this->db->insert(‘category_images’, $data);


      if ($this->session->userdata(‘uploadImages’)=='')// or if (!isset($this->session->userdata(‘uploadImages’)))
      {
      $this->session->set_userdata(‘uploadImages’, $this->db->insert_id());
      }
      else
      {
      $session = $this->session->userdata(‘uploadImages’);
      $sessionData = $session.’|’.$this->db->insert_id();
      $this->session->set_userdata(“uploadImages”, $sessionData);
      } 

      echo $this->session->userdata(‘uploadImages’); // return 256; corect result - 255|256

end of cycle
于 2013-09-06T12:35:42.943 回答