我有一个注册表单,我正在验证用户输入。这是我的控制器:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Register extends CI_Controller {
public function index()
{
$this->load->model('Users_model');
$this->load->helper('form');
$this->load->library('form_validation');
$data['page_title'] = 'Register';
$this->load->view('header', $data);
// Set form validation rules
$this->form_validation->set_rules('username', 'Username', 'trim|required|min_length[5]|max_length[16]|xss_clean|callback_username_check');
$this->form_validation->set_rules('email', 'Email', 'trim|required|min_length[5]|max_length[64]|valid_email|callback_email_check');
$this->form_validation->set_rules('password', 'Password', 'required');
$this->form_validation->set_error_delimiters('<span class="error">', '</span>');
if ($this->form_validation->run() == FALSE)
{
$this->load->view('register', $data);
}
else
{
// Add the user to the database
$this->Users_model->add_user();
$this->load->view('register_success', $data);
}
$this->load->view('footer', $data);
}
/* Functions to check username and email */
}
/* End of file register.php */
/* Location: ./application/controllers/register.php */
问题出在这一行:$this->Users_model->add_user();
. 我想将用户名、电子邮件和密码传递给我的用户模型以将用户添加到我的数据库中,但我不确定如何将 POST 数据获取到该方法中。通常我会使用$_POST['username']
等,但 CodeIgniter 已经在输入值(等)上运行了一些trim()
函数xss_clean
。如何获取这些值并将它们传递到我的add_user()
方法中?