可以';t使用Ion Auth';s在另一个控制器中的登录方法


Can't use Ion Auth's login method in another controller

我在项目中添加了controllers/Site.php、views/Site/login.php,但当我提交登录表单时,我总是得到*/application/views/Site/login#有人知道为什么吗?怎么了?

这是我的网站。hp:

<?php defined('BASEPATH') OR exit('No direct script access allowed');
class Site extends MY_Controller {
function __construct() {
    parent::__construct();
    $this->load->library('ion_auth');
    $this->load->library('form_validation');
    $this->load->helper('url');
    $this->load->helper('string');
    $this->load->database();
    $this->form_validation->set_error_delimiters($this->config->item('error_start_delimiter', 'ion_auth'), $this->config->item('error_end_delimiter', 'ion_auth'));
    $this->lang->load('auth');
    $this->load->helper('language');
    $this->data['pageTitle'] = $this->lang->line('login_page_title');
}
//redirect if needed, otherwise display the user list
function index() {
    if (!$this->ion_auth->logged_in()) {
        //redirect them to the login page
        redirect('site/login', 'refresh');
    } else if (!$this->ion_auth->is_admin()) { //remove this elseif if you want to enable this for non-admins
        //redirect them to the home page because they must be an administrator to view this
        return show_error('You must be an administrator to view this page.');
    }
}
//log the user in
function login() {
    $this->data['title'] = "Login";
    //validate form input
    $this->form_validation->set_rules('identity', 'Identity', 'required');
    $this->form_validation->set_rules('password', 'Password', 'required');
    if ($this->form_validation->run() == true) {
        //check to see if the user is logging in
        //check for "remember me"
        $remember = (bool) $this->input->post('remember');
        if ($this->ion_auth->login($this->input->post('identity'), $this->input->post('password'), $remember)) {
            //if the login is successful
            //redirect them back to the home page
            $this->session->set_flashdata('message', $this->ion_auth->messages());
            redirect('/', 'refresh');
        } else {
            //if the login was un-successful
            //redirect them back to the login page
            $this->session->set_flashdata('message', $this->ion_auth->errors());
            redirect('site/login', 'refresh'); //use redirects instead of loading views for compatibility with MY_Controller libraries
        }
    }
        $this->_render_page('site/login', $this->data);
}
}

这是我的简单登录php:

<!doctype html>
<html>
<head>
<title></title>
</head>
<body>
<h1>Login</h1>
<form role="form" action="#" method="post">
    <div class="input-group">
        <input type="email" id="identity" name="identity" placeholder="Your email address" value="admin@mail.com">
    </div>
    <div class="input-group">
        <input type="password" id="password" name="password" placeholder="Your password" value="password">
    </div>
    <div class="checkbox-group">
        <input type="checkbox" value="1" id="remember" name="remember" data-toggle="checkbox">
        <label for="remember">Remember Me</label>
    </div>
    <button type="submit">Log me in</button>
</form>
</body>
</html>

这个action="#"看起来很奇怪。我认为你应该用action='/site/login'来改变这一点。您不需要使用如上所述的base_url()。相关路径应该足够了。