我正在使用本周发布的 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]); }
}
}
我尝试在线搜索,但不幸的是我找不到任何东西提前谢谢