Я добавил controllers / Site.php, views / site / login.php в свой проект, но когда я отправляю форму входа, я всегда получаю * / application / views / site / login #
Кто-нибудь знает почему? в чем проблема?
вот мой Site.php:
<?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);
}
}
А вот мой простой login.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="[email protected]">
</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()
как прокомментировано выше. Связанного пути должно быть достаточно.
Других решений пока нет …