我正在追踪源文件可以在这里找到:https://github.com/JeffreyWay/Simple-CI-Authentication
现在,当我尝试登录时,它一直循环回来说我有错误,就像在教程视频中他回来一样好,没有显示错误。
I get The Email Address field is required.The Password field is required.
即使我输入了两个有效字段的输入,也就是我的代码:
应用/控制器/ admin.php的
<?php if(! defined('BASEPATH')) exit('No direct script access allowed');
class Admin extends CI_Controller
{
public function index()
{
$this->load->library('form_validation');
$this->form_validation->set_rules('email_address', 'Email Address', 'required|valid_email');
$this->form_validation->set_rules('password', 'Password', 'required|min_length[4]');
if ($this->form_validation->run() !== FALSE)
{
$this->load->model('Admin_model');
$this->Admin_model->verify_user('test@admin.com', 'test');
// then validation passed. get from the db.
}
$this->load->view('login_view');
}
}
应用/视图/ login_view.php
<h1>Login</h1>
<?php echo form_open('admin'); ?>
<p>
<?php
echo form_label('Email Address: ', 'email_address');
echo form_input('Email Address', '', 'id="email_address"');
?>
</p>
<p>
<?php
echo form_label('Password: ', 'password');
echo form_password('Password', '', 'id="password"');
?>
</p>
<?php echo form_submit('submit', 'Login'); ?>
<?php echo form_close(); ?>
<div class="errors"><?php echo validation_errors(); ?></div>
有什么想法吗?
答案 0 :(得分:1)
您需要将视图中的表单输入更改为:
form_input('email_address', '', 'id="email_address"');
form_password('password', '', 'id="password"');
他们的名字必须与您在控制器规则中输入的名称相匹配。