为什么在我使用cakephp 4时找不到表?

时间:2019-12-19 10:43:30

标签: cakephp orm cakephp-4.x

我正在使用本周发布的CakePHP 4,我尝试实现注册表格,但是当我提交表格时,会显示此错误

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

}

我尝试在线搜索,但很遗憾,我无法提前找到任何内容

1 个答案:

答案 0 :(得分:1)

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

另请参见