Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
hwiesmann opened this issue Nov 21, 2018 · 2 comments
Closed

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

hwiesmann opened this issue Nov 21, 2018 · 2 comments

Comments

@hwiesmann
Copy link


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

@samsonasik
Copy link
Member

please try latest develop branch, I can see that it already uses $this->validator->getErrors() at https://github.com/codeigniter4/CodeIgniter4/blob/develop/user_guide_src/source/incoming/controllers.rst#validating-_post-data

@jim-parry
Copy link
Contributor

Agreed, This has already been addressed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants