Codeigniter. Checking PUT Data

I am developing an API using Phils RestServer and I need to check the incoming PUT data. It works great with incoming POST data, but not PUT.

How can I check the data sent via PUT?

Thanks for entering!

+4
source share
4 answers

Nope! Does not work. What you can do is crack it, so:

$_POST['foo'] = $this->put('foo'); 

The permission of the Validation CodeIgniter class for checking objects other than POST is in the task list (for this reason).

+5
source

Here is my solution. I use the set_data () function from the form validation library:

 $set_data = array( 'username' => $this->put('username'), 'email' => $this->put('email'), 'zipcode' => $this->put('zipcode'), 'telephone' => $this->put('telephone'), 'password' => $this->put('password'), ); $this->form_validation->set_data($set_data); $this->form_validation->set_rules($this->Register_model->rules_register); 
+1
source

I realized that after my first answer it all depends on which version of CI you are using, if you are using the latest version 3.0.0 or later, then you can make 1 small setting in the form validation file.

The form_validation.php file at the top of the set_rules () method on line 176

FROM:

 if ($this->CI->input->method() !== 'post' && empty($this->validation_data)) { return $this; } 

TO:

 if ($this->CI->input->method() !== 'post' && $this->CI->input->method() !== 'put' && empty($this->validation_data)) { return $this; } 

Let me know if this helped.

0
source

It works fine using set_data (). Let's say the parameters "MRP" and "IsActive" are sent on request.

 $this->form_validation->set_data($this->put()); $this->form_validation->set_rules('MRP', 'MRP', 'numeric|greater_than[0]|less_than[10000]', array()); $this->form_validation->set_rules('IsActive', 'Is Active', 'required|alpha|min_length[2]|max_length[2]', array()); if ($this->form_validation->run() === TRUE) { // Do Stuff.. } 
0
source

All Articles