简体   繁体   English

在cakephp 3中保存数据

[英]Saving data in cakephp 3

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';
}

As per my comment: 根据我的评论:

Instead of echo'ing error, I would loop through $user->errors() and print those to see what my errors are. 而不是回显错误,我将遍历$user->errors()并打印出来以查看我的错误是什么。 99% chance that it's a validation error. 99%的机会是验证错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM