Automatically inject validation errors from withInput() into view data. Default view to saveData = true for better usability.

This commit is contained in:
Lonnie Ezell 2017-11-25 15:42:47 -06:00
parent 9872a8c2ea
commit 2a781e599b
No known key found for this signature in database
GPG Key ID: 8EB408F8D82F5002
2 changed files with 8 additions and 1 deletions

View File

@ -10,7 +10,7 @@ class View extends \CodeIgniter\Config\View
* calls so that it is available to all views. If that is the case,
* set $saveData to true.
*/
public $saveData = false;
public $saveData = true;
/**
* Parser Filters map a filter name with any PHP callable. When the

View File

@ -117,6 +117,13 @@ if ( ! function_exists('view'))
unset($options['saveData']);
}
// Automatically inject any validation errors into the view
// that may have come from 'redirect()->withInput()'.
if (isset($_SESSION) && ! empty($_SESSION['errors']))
{
$data['errors'] = $_SESSION['errors'];
}
return $renderer->setData($data, 'raw')
->render($name, $options, $saveData);
}