title: CodeIgniter login form not working
body: <p>On my tvs system I try to make a login form. This form should result in a redirect to the admin panel, but something is missing and I could not figure it out. I have already put some information in the database "users" table. But any information from MySQL does not show even when I use var_dump();</p>
  
  <p>My code in controller folder</p>
  
  <pre><code>class User extends Backend_Controller {
  
  public function __construct() {
      parent::__construct();
  }
  
  public function login() {
      $this-&gt;load-&gt;helper('language');
      $this-&gt;lang-&gt;load('form_validation', 'lithuanian');
      $dashboard = 'admin/dashboard';
      $this-&gt;user_m-&gt;loggedin() == FALSE || redirect($dashboard);
      $rules = $this-&gt;user_m-&gt;rules;
      $this-&gt;form_validation-&gt;set_rules($rules);
      if ($this-&gt;form_validation-&gt;run() == TRUE) {
          if ($this-&gt;user_m-&gt;login() == TRUE) {
              redirect($dashboard);
          } else {
              $this-&gt;session-&gt;set_flashdata('error', 'Email/password are wrong');
              redirect('admin/user/login', 'refresh');
          }
      }
      $this-&gt;data['subview'] = 'admin/user/login';
      $this-&gt;load-&gt;view('admin/_layout_modal', $this-&gt;data);
  }
  
  public function logout() {
      $this-&gt;user_m-&gt;logout();
      redirect('admin/user/login');
  }
  </code></pre>
  
  <p>}</p>
  
  <p>In core folder MY_Model.php</p>
  
  <pre><code>class MY_Model extends CI_Model {
  
  protected $_table_name = '';
  protected $_primary_key = 'id';
  protected $_primary_filter = 'intval';
  protected $_order_by = '';
  public $rules = array();
  protected $_timestamps = FALSE;
  
  function __construct() {
      parent::__construct();
  }
  
  public function get($id = NULL, $single = FALSE) {
      if ($id != NULL) {
          $filter = $this-&gt;_primary_filter;
          $id = $filter($id);
          $this-&gt;db-&gt;where($this-&gt;_primary_key, $id);
          $method = 'row';
      } elseif ($single == TRUE) {
          $method = 'row';
      } else {
          $method = 'result';
      }
  
      if (!count($this-&gt;db-&gt;ar_orderby)) {
          $this-&gt;db-&gt;order_by($this-&gt;_order_by);
      }
      return $this-&gt;db-&gt;get($this-&gt;_table_name)-&gt;$method();
  }
  
  public function get_by($where, $single = FALSE) {
      $this-&gt;db-&gt;where($where);
      return $this-&gt;get(NULL, $single);
  }
  
  public function save($data, $id = NULL) {
      //timestamps
      if ($this-&gt;_timestamps == TRUE) {
          $now = date('Y-m-d H:i:s');
          $id || $data['created'] = $now;
          $data['modified'] = $now;
      }
      //insert
      if ($id === NULL) {
          !isset($data[$this-&gt;_primary_key]) || $data[$this-&gt;_primary_key] == NULL;
          $this-&gt;db-&gt;set($data);
          $this-&gt;db-&gt;insert($this-&gt;_table_name);
          $id = $this-&gt;db-&gt;insert_id();
      }
      //update
      else {
          $filter = $this-&gt;_primary_filter;
          $id = $filter($id);
          $this-&gt;db-&gt;set($data);
          $this-&gt;db-&gt;where($this-&gt;_primary_key, $id);
          $this-&gt;db-&gt;update($this-&gt;_table_name);
      }
  
      return $id;
  }
  
  public function delete($id) {
      $filter = $this-&gt;_primary_filter;
      $id = $filter($id);
      if (!$id) {
          return FALSE;
      }
      $this-&gt;db-&gt;where($this-&gt;_primary_key, $id);
      $this-&gt;db-&gt;limit(1);
      $this-&gt;db-&gt;delete($this-&gt;_table_name);
  }
  </code></pre>
  
  <p>}</p>
  
  <p>In model folder user_m.php</p>
  
  <pre><code>&lt;?php
  
  class User_M extends MY_Model {
  
  protected $_table_name = 'users';
  protected $_order_by = 'name';
  public $rules = array(
      'email' =&gt; array(
          'field' =&gt; 'email',
          'label' =&gt; 'Email',
          'rules' =&gt; 'trim|required|valid_email|xss_clean'
      ),
      'password' =&gt; array(
          'field' =&gt; 'password',
          'label' =&gt; 'Password',
          'rules' =&gt; 'trim|required'
      )
  );
  
  function __construct() {
      parent::__construct();
  
  
    }
  
  public function login() {
  
      $user = $this-&gt;get_by(array(
          'email' =&gt; $this-&gt;input-&gt;post('email'),
          'password' =&gt; $this-&gt;hash($this-&gt;input-&gt;post('password')),
              ), TRUE);
      if (count($user)) {
          //log in user
          $data = array(
              'íd' =&gt; $user-&gt;id,
              'email' =&gt; $user-&gt;email,
              'name' =&gt; $user-&gt;name,
              'loggedin' =&gt; TRUE,
          );
          $this-&gt;session-&gt;set_userdata($data);
      }
  }
  
  public function register() {
  
  }
  
  public function logout() {
      $this-&gt;session-&gt;sess_destroy();
  }
  
  public function loggedin() {
      return (bool) $this-&gt;session-&gt;userdata('loggedin');
  }
  
  public function hash($string) {
      return hash('sha512', $string . config_item('encryption_key'));
  }
  </code></pre>
  
  <p>}</p>
  
  <p>And in the view folder login.php </p>
  
  <pre><code>&lt;?php
  if (validation_errors() !== '') {
      echo "&lt;div class='alert alert-warning alert-dismissible' role='alert'&gt; &lt;button type='button' class='close' data-dismiss='alert'&gt;&lt;span aria-hidden='true'&gt;&amp;times;&lt;/span&gt;&lt;span class='sr-only'&gt;Close&lt;/span&gt;&lt;/button&gt; &lt;strong&gt;Warning!&lt;/strong&gt;";
      echo validation_errors();
      echo "&lt;/div&gt;";
  }
  ?&gt;
  &lt;?php echo form_open(); ?&gt;
  &lt;div class="form-signin"&gt;
      &lt;?php
      $data = array(
          'name' =&gt; 'email',
          'class' =&gt; 'form-control',
          'placeholder' =&gt; 'Email'
      );
      echo form_input($data);
      $data = array(
          'name' =&gt; 'password',
          'class' =&gt; 'form-control',
          'placeholder' =&gt; 'Password'
      );
      echo form_password($data);
      echo form_submit('submit', $login, 'class="btn btn-lg btn-primary"');
      echo anchor('admin/user/auth/forgot_password', $forget_password, 'class="pull-right"');
      ?&gt;
  &lt;/div&gt;
      &lt;?php echo form_close(); ?&gt;
  </code></pre>