title: Codeigniter loading a library in a static function
body: <p>I have a static function in my users_model, called isLoggedin(), that needs a library I made. I can't get it to load! It's in the libraries folder under the name SessionsHelper.php and has a class SessionsHelper in it(unsurprising I know). I tried loading it in the static function with <code>$this-&gt;load-&gt;library('SessionsHelper')</code> only to find that I can't use $this in a static function. Then I tried to load it using <code>require_once '../libraries/SessionsHelper.php'</code> which didn't work, then I tried the autoloader, which didn't work either.... so here's the function.</p>
  
  <pre><code>public static function isLoggedin() {
          if (SessionsHelper::get('id') != '' &amp;&amp; SessionsHelper::get('id') &gt;= 0) { // TODO add logic to differentiate between user/admin
              return true;
          }
          return false;
      }
  </code></pre>
  
  <p>I just need to be able to use the library! Please any help would be very appreciative!</p>
  
  <p>EDIT:
  The controller is:</p>
  
  <pre><code>class Users extends CI_Controller{
  
      public function login(){
          $this-&gt;load-&gt;model('users_model');
  
          if($this-&gt;users_model-&gt;isLoggedin()){
              redirect($this-&gt;config-&gt;base_url);
          }
  
          $data['info'] = $this-&gt;users_model-&gt;login('slavigne@uark.edu', 'abcdefg');
  
          $this-&gt;load-&gt;view('templates/header');
          $this-&gt;load-&gt;view('users/login', $data);
          $this-&gt;load-&gt;view('templates/footer');
      }
  
      public function logout(){
          $this-&gt;load-&gt;library('SessionHelper');
          SessionsHelper::destroy();
      }
  }
  </code></pre>
  
  <p>the model is:</p>
  
  <pre><code>class users_model extends CI_Model{
      public function users_model(){
              parent::__construct();
      }
  
      public static function hash($password, $salt) {
  //this code works no problem! but it's private you know?
      }
  
      public static function isLoggedin() {
          $CI =&amp; get_instance();
          $CI-&gt;load-&gt;library('SessionsHelper');
          if (SessionsHelper::get('id') != '' &amp;&amp; SessionsHelper::get('id') &gt;= 0) { // TODO add logic to differentiate between user/admin
              return true;
          }
          return false;
      }
  
      public function login($email, $password){
          $this-&gt;load-&gt;library('SessionHelper');
          $this-&gt;load-&gt;database();
          $query = $this-&gt;db-&gt;get_where('users', array('email' =&gt; $email));
          $result = $query-&gt;result();
          if($result[0]-&gt;password == $this-&gt;hash($password, $result[0]-&gt;salt)){
              //error_log("Pass matched!");
              SessionHelper::set('id', $result[0]-&gt;id);
          }        
          return $result[0];
      }
  }
  </code></pre>
  
  <p>the library is and is in application/libraries/Sessinshelper.php:</p>
  
  <pre><code>class Sessionshelper {
          public function __construct() {      
      }
  
      public static function start() {
          if (!session_id()) {
              session_start();
          }
      }
  
      public static function set($fld, $val) {
          self::start();
          $_SESSION[$fld] = $val;
      }
  
      public static function un_set($fld) {
          self::start();
          unset($_SESSION[$fld]);
      }
  
      public static function destroy() {
          if (session_id() != "" || isset($_COOKIE[session_name()])) {
              $params = session_get_cookie_params();
              setcookie(session_name(), '', time() - 42000, $params["path"], $params["domain"], $params["secure"], $params["httponly"]);
          }
          session_unset();
          $_SESSION = array();
          session_destroy();
      }
  
      public static function get($fld) {
          self::start();
          if (isset($_SESSION[$fld])) {
              return $_SESSION[$fld];
          }
          return FALSE;
      }
  }
  </code></pre>