当我包含$ this-> load-> library('session'); 属性会话将自动销毁

whenever i add $this->load->library('session'); property in code igniter function the session will destroy automatically .. please help me about this..

controller function:

public function logged()
{    
   $this->load->library('session');
   $this->load->view('includes/header');
   $this->load->view('includes/nav');
   $this->load->view('index'); 
   $this->load->view('includes/footer');
}

view page:

<h4><?php echo $this->session->flashdata('item'); ?></h4>

Error: A PHP Error was encountered

Severity: Notice

Message: Undefined property: CI_Loader::$session

Filename: views/index.php

Line Number: 6

Backtrace:

File: C:\xampp\htdocsavi2\application\views\index.php Line: 6 Function: _error_handler

File: C:\xampp\htdocsavi2\application\controllers\welcome.php Line: 19 Function: view

File: C:\xampp\htdocsavi2\index.php Line: 315 Function: require_once

Two suggestions:
1) Maybe just auto-load the session library in the autoload config file.

$autoload['libraries'] = array('database', 'email', 'session');

OR, maybe you are by default and the secondary load in the controller function is killing the initial load.

2) If you can't autoload the session library, then maybe load it in the construct of the controller that the logged function is in.

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

    $this->load->library('session');    
}

If you don't want to add session library in autoload.php than load manually in your controller constructor as:

$this->load->library('session');

Most Important from the Manual: Because the Loader Class is instantiated by CodeIgniter’s base controller, make sure to call parent::__construct() before trying to load a library from inside a controller constructor.

public function __construct()
{
    parent::__construct();
    $this->load->library('session');
}

And in view you can use like:

if($this->session->flashdata('item')){
   // to do
}

You have to set the flash data before viewing it, imo you're trying to echo the flashdata while its not set, this is how to use your sessions, first either load the session using the construct function on your controller using the :

 $this->load->library('session');   

or auto-load the session helper in your libraries autoload, then set the flash data like so :

 $this->session->set_flashdata("flashdataname", "data");

Then always check if the flashdata is set before trying to echo it, ex :

if (!empty($this->session->flashdata("flashdataname"))) 
echo ....

Load the session library in your constructor {magic method}

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Controller extends CI_Controller {
public function __construct() {
    parent::__construct();
    $this->load->library('session');
}
public function logged() {  
    $this->load->view('includes/header');
    $this->load->view('includes/nav');
    $this->load->view('index'); 
    $this->load->view('includes/footer');
  }
}