0

我正在使用本周发布的 CakePHP 4,我试图实现一个注册表单,但是当我提交表单时出现此错误

在此处输入图像描述

在此处输入图像描述

 public function register()
{
    if($this->request->is('post')){
        $userTable = TableRegistry::getTableLocator()->get('Users');
        $user = $userTable->newEntity();

        $hasher = new DefaultPasswordHasher();
        $myname = $this->request->getData('firstName');
        $myemail = $this->request->getData('email');
        $mypass = Security::hash($this->request->getData('password'),'sha256', false);
        $mytoken = Security::hash(Security::randomBytes(32));

        $user->name = $myname;
        $user->email = $myemail;
        $user->password - $hasher->hash($mypass);
        $user->token = $mytoken;
        $user->created_at = date('Y-m-d H:i:s');
        $user->update_at = date('Y-m-d H:i:s');
        if($userTable->save($user)){
            $this->flash->set("Register successful, your connfirmation email has been sent", ['elemennt'=>success]);

            TransportFactory::setConfig('mailtrap', [
              'host' => 'smtp.mailtrap.io',
              'port' => 2525,
              'username' => '4c4a87ef71fb4a',
              'password' => 'a7c681d69ddac7',
              'className' => 'Smtp'
            ]);

            $email = new Email('default');
            $email->transport('mailtrap');
            $email->emailFormat('html');
            $email->from('mezigan@gmail.com','Alastair Micallef');
            $email->subject('Please confirm your email to activation your accout');
            $email->to($myemail);
            $email->send('hai '.$myname.'<br/>Please confirm your email link below<br/><a href="http://localhost:/users/verification/'.$mytoken.'">Verification Email</a>Thanks you for joining us');
        }else{
            $this->flash->set("Register failed,please try agai", ['elemennt'=>error]);            }
    }

}

我尝试在线搜索,但不幸的是我找不到任何东西提前谢谢

4

1 回答 1

2

\Cake\ORM\Table::newEntity()在 4.x 中没有输入就不能工作了。如果您想创建空实体,您现在必须使用该\Cake\ORM\Table::newEmptyEntity()方法,该方法为此目的而明确提及。

也可以看看

于 2019-12-19T12:11:25.337 回答