You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Oh im fix me problem with change validate() with my validateCustom() to base controller.
BaseController:
/** * A shortcut to performing validation on input data. If validation * is not successful, a $errors property will be set on this class. * * @param array|string $rules * @param array|string $data * @param array $messages An array of custom error messages * * @return boolean */protectedfunctionvalidateCustom($rules, $data, array$messages = []): bool
{
$this->validator = Services::validation();
// If you replace the $rules array with the name of the groupif (is_string($rules)) {
$validation = config('Validation');
// If the rule wasn't found in the \Config\Validation, we// should throw an exception so the developer can find it.if (!isset($validation->$rules)) {
throw ValidationException::forRuleNotFound($rules);
}
// If no error message is defined, use the error message in the Config\Validation fileif (!$messages) {
$errorName = $rules . '_errors';
$messages = $validation->$errorName ?? [];
}
$rules = $validation->$rules;
}
return$this->validator
->setRules($rules, $messages)
->run($data);
}
My own controller:
<?phpnamespaceApp\Controllers;
useCodeIgniter\Controller
class AuthenticationController extends Controller
{
/** * Register New Users from POST Requests to /api/users. * * @return \CodeIgniter\HTTP\Response */publicfunctionregister()
{
$request = $this->request->getJSON();
if (! $this->validateCustom(static::rules(), (array) $request->user))) {
return$this->response->setJSON([
'errors' => $this->validator->getErrors()
])
->setStatusCode(422);
}
}
}
Describe the bug
When request with raw body, this validation didn't capture request, and will be missing input.
CodeIgniter 4 version
v4.0.4
Affected module(s)
CodeIgniter\Validation\Validation
Context
The text was updated successfully, but these errors were encountered: