如何在CakePHP中将数据从表单传递到控制器?

时间:2015-07-04 07:37:54

标签: cakephp

如何将表单中的数据传递给控制器​​,然后将该数据传递给模型

public function registertest()
    {

    if (!empty($this->data)) {

        var_dump($this->data);

        if ($this->data['User']['password'] == $this->Auth->password($this->data['User']['cpassword'])) {
            $this->User->create();

            if($this->User->save($this->data)) {
                $this->Auth->login($this->data);
                $this->redirect(array('action' => 'index'));
            }
        }
    }
    //$this->render('register');
}

1 个答案:

答案 0 :(得分:0)

使用此代码

 public function registertest()
    {
    if ($this->request->is('post')) {
       $this->data['User']['password'] == $this->Auth->password($this->data['User']['cpassword']);
       $this->User->create();

        if($this->User->save($this->request->data['User'])) {
            $this->Auth->login($this->request->data['User']);

            $msg = '<div class="alert alert-success">
            <button type="button" class="close" data-dismiss="alert">&times;</button>
            <strong> User Created succeesfully </strong>
            </div>';
            $this->Session->setFlash($msg);
            $this->redirect(array('action' => 'index'));
        }



        }
}