Skip to content

[Documentation] Bug in code example for "Validating $_POST data" #1520

Description

@hwiesmann

name: Bug report
about: Bug (misleading code) in example for "Validating $_POST data"


Describe the bug

The following code is mentioned in "Validating $_POST data":

`public function updateUser(int $userID)
{
if (! $this->validate([
'email' => "required|is_unique[users.email,id,{$userID}]",
'name' => 'required|alpha_numeric_spaces'
]))
{
return view('users/update', [
'errors' => $this->errors
]);
}

// do something here if successful...

}`

This code gives the impression that the controller class has a variable called "$errors" but this is not the case.

A solution is to use \Config\Services::validation()->getErrors() instead of $this->errors.

PS: The same applies for the second example code in the same section!

CodeIgniter 4 version
CodeIgniter 4 Alpha 2

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions