为什么我在CakePHP中出现错误,以空值调用成员函数_setnew()?

问题描述 投票:-1回答:1

我有一个小问题。我是一个初学者,我坚持这一点。我有一个注册表来注册用户。但是在提交按钮后,我有一个错误:

在null上调用成员函数_setnew()错误:发生内部错误。

堆栈跟踪[内部功能]→StronaController-> registry()CORE \ Cake \ Controller \ Controller.php第499行→ReflectionMethod-> invokeArgs(StronaController,array)CORE \ Cake \ Routing \ Dispatcher.php第193行→Controller-> invokeAction(CakeRequest)CORE \ Cake \ Routing \ Dispatcher.php第167行→Dispatcher-> _ invoke(StronaController,CakeRequest)APP \ webroot \ index.php第117行→Dispatcher-> dispatch(CakeRequest,CakeResponse)

这是我的代码:

<form class="mainForm" method="POST" action="">
  <input type="text" name="data[User][email]" placeholder="Login">
    <br>
  <input type="password" name="data[User][password]" placeholder="Passwort">
    <br>
  <input type="submit" value="Registrieren">                        
</form>
public function registry() {
        $el = array();
        $el['helper']['menu'] = 'registry';
        $el['helper']['title'] = 'Registrierung';
        $el['helper']['meta'] = '<title>Kogni-fit / Registrierung</title>
        <meta name="identifier-url" content="https://kogni-fit.at/registrierung" />
        <meta name="description" content="Kogni-Fit">';

        if($this->request->is('post')) {
            $data = $this->data;
            //TUTAJ POWINNA BYĆ WALIDACJA!
            $this->User->_setnew($data['User']);
            //$this->vd($data);

            // Przekierowanie z komentarzem

            $this->Session->setFlash('Benutzer hinzugefügt');
            $this->redirect(array('action'=>'logowanie'));

        }

        $this->set('el',$el);
    }
class CmsController extends AppController {

public function beforeFilter() {
        parent::beforeFilter();
        $this->layout = 'cms';
        //$this->Auth->allow();
        $this->Auth->allow('blog');
        $check_user = $this->Auth->user();

        if($check_user['role'] != 'admin') {

            $this->redirect(array('action'=>'index', 'controller'=>'strona'));
        }

    }
}
class User extends AppModel {

    public function _setnew($user) {

        //$this->data[$this->alias]['password'] = AuthComponent::password($this->data[$this->alias]['password']);
        $user['password'] = AuthComponent::password($user['password']); //hashuje hasło przed zapisem do bazy

        $this->save($user);
    }
}

感谢您的帮助

php cakephp-2.0
1个回答
0
投票

尝试打印$data数组。似乎没有键'User'

的元素
© www.soinside.com 2019 - 2024. All rights reserved.