CodeIgniter会话未设置

The session is not set in the following case. It was working for me earlier. I am using CodeIgniter.

 public function authenticate(){
    $user = new Entity\User;
    //$user2 = new Entity\User;
    $user->username = "prayag@gmail.com";
    $user->password = "prayag";
    $userRepository = $this->doctrine->em->getRepository('Entity\User');
    $checkLogin = $userRepository->checkLogin($user);
    echo "Username => ". $checkLogin[0]->username;
    echo "ID => ". $checkLogin[0]->id;
    $this->load->library('session');
    $this->session->sess_destroy();

    if(!empty($checkLogin)){
        $CI =& get_instance();
        $this->session->set_userdata('user_id',$checkLogin[0]->id);

        $loggedIn = $this->session->set_userdata('user_id');    
            if($loggedIn !== TRUE){
                echo "session is not set";
                //echo $this->session->set_userdata('user_id');
            } else {
                    echo "session is set";
            }
        }
        else{
            echo "Username not found";  
        }
    }

I tried to solve it using the following post: https://stackoverflow.com/questions/10712250/w hat-is-the-proper-way-to-test-codeigniter-session-variable

did u load the session library

i.e. $this->load->library('session');

also, convert the code

$loggedIn = $this->session->set_userdata('user_id');    
            if($loggedIn !== TRUE){
                echo "session is not set";
                //echo $this->session->set_userdata('user_id');
            } else {
                    echo "session is set";
            }
        }

to

if($this->session->userdata('user_id')!=true)
   {
        echo "session is not set";
                //echo $this->session->set_userdata('user_id');
   } 
else 
{
    echo "session is set";
 }

After $this->session->sess_destroy();

Shouldn't be something like session_start(); ?

Or what's the point to destroy session in the middle of code?

change this line

$loggedIn = $this->session->set_userdata('user_id');  

to

$loggedIn = $this->session->userdata('user_id');