Codeigniter表单验证

Here is my controller

  function register(){
        $_POST['username'] = $_GET['username'];
                $this->load->library('form_validation');
                $this->load->helper('form');
        $this->form_validation->set_rules('username', 'username', 'required|trim|xss_clean|min_length[5]');
        if($this->form_validation->run())
        {

        }
        var_dump(form_error('username'));
}

Can I test this funtion with home/register?username=test ??? I tried but it not working

Well, apart from you question being a bit confusing, I think the answer is no. You cannot test a post request with a get request from url parameters.

The way to test a post request is to post the required test data.

I am pretty sure that is correct, however, as I said your question was a bit confusing so if I am missing your point, I apologize in advance.

If you want to test validation NOT from a post, you can use the validation rules on any array.

$data = array(
    'username' => 'johndoe',
    'password' => 'mypassword',
    'passconf' => 'mypassword'
);

$this->form_validation->set_data($data);

You can read more about that here: http://www.codeigniter.com/user_guide/libraries/form_validation.html#validating-an-array-other-than-post