0
votes

I want to save User data in my database but still getting error

data

$this->request->data['nickname'] = ' asd';
$this->request->data['first_name'] = ' asd';
$this->request->data['last_name'] = 'asd ';

controller

$user = $this->Users->newEntity();

$user = $this->Users->patchEntity($user, $this->request->data);

if ($this->Users->save($user)) {
       echo 'saved';
} else {
       echo 'error';
}
1
What's you error ? - Alimon Karim
newEntity is wasted if you are overwriting it with a patched entity. also, instead of echo'ing error, I would loop through $user->errors() and print those to see what my errors are. 99% chance that it's a validation error. But we need more data. - Bird87 ZA
@Albert Yep, it was validation, thanks for your help! - Łukasz Skup

1 Answers

0
votes

As per my comment:

Instead of echo'ing error, I would loop through $user->errors() and print those to see what my errors are. 99% chance that it's a validation error.