title: HOW to set_userdata login codeigniter
body: <p>I get Message error: Trying to get property of non-object, and i dont know solved this problem. please help</p>
  
  <p><strong>CONTROLLER</strong></p>
  
  <pre><code>public function login_user(){
       $user =array( 'email_user'=&gt; $this-&gt;input-&gt;post('email_user'),
              'password_user'=&gt; $this-&gt;input-&gt;post('password_user'));
       $myquery= $this-&gt;user_model-&gt;login_check($user['email_user'], 
               $user['password_user']);
   if ($myquery== TRUE) {
       foreach($myquery as $d){ 
           $session_array = array(
                 'id_user'=&gt;$d-&gt;id_user,
                 'username_user'=&gt;$d-&gt;username_user,
                 'email_user'=&gt;$d-&gt;email_user,
                 'phone_user'=&gt;$d-&gt;phone_user,
                 'tanggal_lahir'=&gt;$d-&gt;tanggal_lahir
           );
           $this-&gt;session-&gt;set_userdata('loggedIn',$session_array);}
           $this-&gt;load-&gt;view('v_formluar.php');
        }
        else{
          $this-&gt;session-&gt;set_flashdata('error_msg', 'Error occured,Try again.');
          $this-&gt;load-&gt;view('v_login.php');
        }
   }
  </code></pre>
  
  <p>I don't know to get data from model to controller, </p>
  
  <p><strong>MY MODEL</strong></p>
  
  <pre><code>public function login_check($email, $password){
  
     $this-&gt;db-&gt;select('registrasi.user_id,
                        registrasi.username_user,
                        registrasi.email_user,
                        registrasi.password_user')
        -&gt;from('registrasi')
        -&gt;where("registrasi.email_user = '$email' OR registrasi.username_user = '$email' ");
  
       $query = $this-&gt;db-&gt;get();
  
      if($query-&gt;num_rows() == 1){
          return $query-&gt;row();
      } else {
          return false;
      }
  } 
  </code></pre>