0

I'm using CakePHP 4 which come out this week and i tried to implement a registration form but when i submit the form this error shows up

enter image description here

enter image description here

 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]);            }
    }

}

i tried searching online but unfortunately i could not find anything thanks in advance

ndm
  • 59,784
  • 9
  • 71
  • 110

1 Answers1

2

\Cake\ORM\Table::newEntity() doesn't work without input anymore in 4.x. If you want to create empty entities, you now you have to use the \Cake\ORM\Table::newEmptyEntity() method, which is explicitly ment for that purpose.

See also

ndm
  • 59,784
  • 9
  • 71
  • 110