Skip to content

Commit fddc794

Browse files
authored
Merge pull request #383 from kenjis/fix-ValidationException-withErrors
fix: redirect()->withInput() causes ValidationException
2 parents a3ea677 + f0b5512 commit fddc794

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/Models/CheckQueryReturnTrait.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ private function checkQueryReturn($return): void
3232

3333
private function checkValidationError(): void
3434
{
35-
$validationErrors = $this->validation->getErrors();
35+
$validationErrors = $this->getValidationErrors();
3636

3737
if ($validationErrors !== []) {
3838
$message = 'Validation error:';
@@ -45,6 +45,27 @@ private function checkValidationError(): void
4545
}
4646
}
4747

48+
/**
49+
* Gets real validation errors that are not saved in the Session.
50+
*
51+
* @return string[]
52+
*/
53+
private function getValidationErrors(): array
54+
{
55+
// @TODO When CI v4.3 is released, you don't need this hack.
56+
// See https://github.com/codeigniter4/CodeIgniter4/pull/6384
57+
return $this->getValidationPropertyErrors();
58+
}
59+
60+
private function getValidationPropertyErrors(): array
61+
{
62+
$refClass = new ReflectionObject($this->validation);
63+
$refProperty = $refClass->getProperty('errors');
64+
$refProperty->setAccessible(true);
65+
66+
return $refProperty->getValue($this->validation);
67+
}
68+
4869
private function disableDBDebug(): void
4970
{
5071
if (! $this->db->DBDebug) {

0 commit comments

Comments
 (0)