I am using Phil Sturgeon's REST server, CI3 and POSTMAN for debugging. I send a PUT with below info, however, I am not receiving the error messages expected.
Here is my form_validation.php:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
$config = array(
'student_put' => array(
array('field' => 'email_address', 'label' => 'email_address', 'rules' => 'trim|required|valid_email'),
array('field' => 'password', 'label' => 'password', 'rules' => 'trim|required|min_length[8]|max_length[16]'),
array('field' => 'first_name', 'label' => 'first_name', 'rules' => 'trim|required|max_length[50]'),
array('field' => 'last_name', 'label' => 'last_name', 'rules' => 'trim|required|max_length[50]'),
array('field' => 'phone_number', 'label' => 'phone_number', 'rules' => 'trim|required|alpha_dash'),
)
);
?>
Here is my method in my controller Api.php:
function student_put(){
$this->form_validation->set_data($this->put());
// these are the rules set in config/form_validation.php
if ($this->form_validation->run('student_put') != FALSE) {
die('good data');
} else {
$this->response(
array(
'status'=> 'failure',
'message'=> $this->form_validation->get_errors_as_array(),
),
REST_Controller::HTTP_BAD_REQUEST
);
}
}
This is in my libraries folder as MY_Form_validation.php:
<?php
class MY_Form_validation extends CI_Form_validation {
function __construct($rules = array()) {
parent::__construct($rules);
$this->ci =& get_instance();
}
public function get_errors_as_array() {
return $this->_error_array;
}
public function get_config_rules() {
return $this->_config_rules;
}
public function get_field_names($form) {
$field_names = array();
$rules = $this->get_config_rules();
$rules = $rules[$form];
foreach ($rules as $index=> $info) {
$field_names[] = $info['field'];
}
return $field_names;
}
}
When I put following in POSTMAN:
X-API-KEY 123456
first_name test
email_address abc
This is the result I get:
{
"status": "failure",
"message": []
}
But I should be getting the validation errors.
As debugging steps, I have confirmed: - no auth errors - the form_validation.php is being read - if I change:
'message'=> $this->form_validation->get_errors_as_array(),
to
'message'=> 'test',
the postman returns:
{
"status": "failure",
"message": "test"
}
Any help very much appreciated.