2015-03-17 2 views
0

Когда пользователь пытается войти в систему, я пытаюсь проверить статус. Если статус равен 0, то перенаправляет обратно администратору. И тогда, если статус 1 перенаправляется на панель.Проверка статуса входа в систему не работает. Codeigniter

Я испытал это все еще держал меня послал меня к приборной панели, даже хотя статус 0

Var самосвала массива (1) {[ "Статус"] => строка (1) "0"} *

Что было бы лучшим решением для проверки статуса моего входа в систему.

Модель Функция

public function getStatus() { 
    $this->db->select('status'); 
    $this->db->from($this->db->dbprefix . 'user'); 
    $this->db->where('username', $this->input->post('username')); 
    $query = $this->db->get(); 

    return $query->row_array(); 
} 

Контроллер

<?php if (! defined('BASEPATH')) exit('No direct script access allowed'); 

class Login extends Admin_Controller { 


    public function index() { 
     $this->form_validation->set_rules('username', 'Username', 'required|callback_validate'); 
     $this->form_validation->set_rules('password', 'Password', 'required'); 

     if ($this->form_validation->run($this) == FALSE) { 

      $this->load->view('template/common/login.tpl', $this->data); 

     } else { 

      $this->load->model('admin/user/model_user'); 

      var_dump($this->model_user->getStatus()); 

      // array(1) { ["status"]=> string(1) "0" } 

      exit; 

      if ($this->model_user->getStatus()) { 

       redirect('admin/dashboard'); 

      } else { 

       $this->session->set_flashdata('error', 'You have not been enabled by the webmaster. Please wait up to 24/48 hours. If you need to contact the website master email' .' '. config_item('config_email')); 

       redirect('admin'); 

      } 
     } 

     } 
    } 

    public function validate() { 
     $this->load->library('user'); 
     if ($this->user->login() == FALSE) { 
      $this->form_validation->set_message('validate', '<i class="fa fa-exclamation-triangle"></i> Does not match any of our database records!'); 
      return false; 
     } else { 
      return true; 
     } 
    } 
} 
+1

перенаправлении на приборной панели 'irrespective', что возвращается. если его не пусто. –

+0

Я попробовал $ this-> model_user-> getStatus() == true, а также $ this-> model_user-> getStatus() == 1 не повезло – user4419336

+0

'$ data = $ this-> model_user-> getStatus(); if ($ data ['status'] == 1) // перенаправлять на панель инструментов –

ответ

0

Проблема решена, я должен был удалить пару вещей из контроллера и модели.

Модель

public function getStatus() { 
    $this->db->where('username', $this->input->post('username')); 
    $query = $this->db->get($this->db->dbprefix . 'user'); 
    $ret = $query->row(); 
    return $ret->status; 
} 

Контроллер

<?php if (! defined('BASEPATH')) exit('No direct script access allowed'); 

class Login extends Admin_Controller { 

private $error = array(); 

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

public function index() { 

    $data['title'] = 'Administration'; 

    $this->form_validation->set_rules('username', 'Username', 'required|callback_validate'); 
    $this->form_validation->set_rules('password', 'Password', 'required'); 

    if ($this->form_validation->run($this) == FALSE) { 

     $this->load->view('template/common/login.tpl', $data); 

    } else { 

     $this->load->model('admin/user/model_user'); 

     if ($this->model_user->getStatus() == 1) { 

      redirect('admin/dashboard'); 

     } else { 

      $this->session->set_flashdata('error', 'You have not been enabled by the webmaster. Please wait up to 24/48 hours. If you need to contact the website master email' .' '. config_item('config_email')); 

      redirect('admin'); 

     } 

    } 

} 

public function validate() { 

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

    if ($this->user->login() == FALSE) { 

     $this->form_validation->set_message('validate', '<i class="fa fa-exclamation-triangle"></i> Does not match any of our database records!'); 

     return false; 

    } else { 

     return true; 
    } 
} 
} 
Смежные вопросы