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
Describe the bug
When using validation placeholders in a model and validating data, the placeholder is not being replaced with the actual data. The validation therefore returns false.
CodeIgniter 4 version
4.0.2
Expected behavior, and steps to reproduce if appropriate
Using the myth-auth package and the GroupModel. Validation rules are defined in the model as:
When trying to update a group in the controller using an already existing name in the database:
$groupModel = new GroupModel();
if (! $this->validate($rules = $groupModel->getValidationRules())) {
return redirect()->back()->withInput()->with('errors', $groupModel->errors());
}
The validation returns false. Looking at the DB (MySQL) query ran it can be seen why: SELECT 1 FROM `auth_groups` WHERE `name` = 'admin' AND `name` != '{name}' LIMIT 1
A manual replacement of {name} with the actual value resolves the issue.
The text was updated successfully, but these errors were encountered:
nControl88
added
the
bug
Verified issues on the current code behavior or pull requests that will fix them
label
Apr 9, 2020
When the fillPlaceholders() is added to the Controller class and called before the validator runs, the issue is solved:
// Replace any placeholders (i.e. {id}) in the rules with
// the value found in $data, if exists.
$rules = $this->fillPlaceholders($rules, $this->request->getVar());
$success = $this->validator
->withRequest($this->request)
->setRules($rules, $messages)
->run();
Describe the bug
When using validation placeholders in a model and validating data, the placeholder is not being replaced with the actual data. The validation therefore returns false.
CodeIgniter 4 version
4.0.2
Expected behavior, and steps to reproduce if appropriate
Using the myth-auth package and the GroupModel. Validation rules are defined in the model as:
When trying to update a group in the controller using an already existing
name
in the database:The validation returns false. Looking at the DB (MySQL) query ran it can be seen why:
SELECT 1 FROM `auth_groups` WHERE `name` = 'admin' AND `name` != '{name}' LIMIT 1
A manual replacement of
{name}
with the actual value resolves the issue.The text was updated successfully, but these errors were encountered: