2
我在我的項目中添加了controllers/Site.php,views/site/login.php,但是當我提交登錄表單時,我總是得到*/application/views/site/login # 有誰知道爲什麼?有什麼問題?在另一個控制器中無法使用Ion Auth的登錄方法
這裏是我的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>
表單動作要'動作=;' – Tpojka
致命錯誤 「」:調用未定義函數BASE_URL() –
奇怪。如果url助手不可用/加載,則會出錯。你的代碼指出url helper已被加載。檢查問題是否發生,因爲它被加載了兩次(即在自動載入文件和控制器中)。如果是這樣,請在'APPPATH中自動加載它。 'config/autoload.php'只。 – Tpojka