我将此控制器设置为登录:
<?php
class Login extends Controller {
function __construct() {
parent::Controller();
$this->form_validation->set_error_delimiters('', '');
$this->output->enable_profiler(TRUE);
}
function index(){
redirect('/login/terminal');
}
function terminal() {
// terminal login
$this->form_validation->set_rules(array('username','password'), 'Username', 'callback_terminal_login_check[$username,$password]');
if ($this->form_validation->run() == FALSE) {
$this->load->view('login_header');
$this->load->view('login_terminal');
$data['version'] = $this->master->GetVersion();
$this->load->view('login_footer', $data);
} else {
redirect('/terminal');
}
}
function terminal_login_check($username,$password) {
// callback function to perform terminal login
if ($this->authentication->DoTerminalAuthentication($username,$password)) {
echo $username;
return TRUE;
} else {
$this->form_validation->set_message('terminal_login_check', 'Invalid');
return FALSE;
}
}
}
Run Code Online (Sandbox Code Playgroud)
我正在看的是执行表单验证回调>>的行 $this->form_validation->set_rules(array('username','password'), 'Username', 'callback_terminal_login_check[$username,$password]');
我知道这不对.基本上我想要做的是检查Authentication-> DoTerminalAuthentication模型的用户名和密码来处理用户的登录.我想传递$username和$password表单字段.这是我的表单视图,如果它有帮助:
<div id="title">Terminal Login</div>
<?php
if (validation_errors()) {
echo '<div id="error">' . validation_errors() . '</div>';
}
?>
<?=form_open('login/terminal');?>
<?=form_label('Username', 'username')?><br />
<?=form_input(array('id'=>'username','name'=>'username','value'=>set_value('username')))?><br />
<?=form_label('Password', 'password')?><br />
<?=form_password(array('id'=>'password','name'=>'password'))?><br />
<?=form_submit(array('name'=>'passwordsubmit','value'=>'Login >>'))?><br />
<?=form_close();?>
Run Code Online (Sandbox Code Playgroud)
Nic*_*ett 10
在控制器中使用它来设置验证规则.
$this->form_validation->set_rules('username', 'Username', 'required');
$this->form_validation->set_rules('password', 'Password', 'required|callback_terminal_login_check');
Run Code Online (Sandbox Code Playgroud)
还有一个像这样的回调.如果要将发布数据与数据库进行比较,我会使用模型.
function terminal_login_check()
{
$username = $this->input->post('username');
$password = $this->input->post('password');
// LOAD MODEL HERE
if ($this->authentication->DoTerminalAuthentication($username, $password))
{
echo $username;
return TRUE;
}
else
{
$this->form_validation->set_message('terminal_login_check', 'Invalid');
return FALSE;
}
}
Run Code Online (Sandbox Code Playgroud)
编辑2013-07-09:为密码验证规则添加了必填字段,因此如果有人不添加密码,您不必点击数据库.
据我了解,表单验证在逐个字段的基础上工作.为了达到你想要的效果,我会将回调附加到其中一个字段(可能是密码字段最好),然后使用全局POST数组访问其他表单字段数据.这样您就不需要将任何内容作为参数传递给回调函数.
| 归档时间: |
|
| 查看次数: |
19254 次 |
| 最近记录: |