2

嗨,我在控制器中有这个方法

 public function registeruser($data){
    var_dump($data);
    if(($data) && ($this->User->create($data))) {
      if($data['User']['password'] != Security::hash($data['User']['confirm_password'], null, true) ){
        $this->Session->setFlash('las contraseñas no coinciden');
        // unset($this->data['User']['password']);
        // unset($this->data['User']['confirm_password']);
        $this->redirect('index');
      }
      else if($this->User->save($data)) {
         $this->_subscribMailchimp($data);

      }else {
        $this->Session->setFlash('El mail no es valido o ya está registrado.');
        unset($data['User']['password']);
        unset($data['User']['confirm_password']);
        $this->redirect('index');
      }
    }else {
      $this->Session->setFlash('No se ha podido registrar.');
      $this->redirect('index');
    }
    return $this->User->getLastInsertID();
}

我需要通过 $data 表单测试控制器

    $data = array('User' => array('name' => 'Luis jose',
                                  'address' => 'el quinto pino',
                                  'zip' => '28012',
                                  'city' => 'Madrid',
                                  'province' => '5',
                                  'email' => 'luis@hotmail.com',
                                  'password' => Security::hash(Configure::read('Security.salt') . '12345'),
                                  'confirm_password' => '12345'));
    $this->testAction('/users/registeruser', array('data' => $data, 'method' => 'get'));

我试过这个数组('data' => $data,'method' => 'get')。控制器函数没有接收到数组

4

1 回答 1

0

您的注册用户需要 1 个参数 ($data),因此 URL 应如下所示:

/foo/registeruser/bar

这将用'bar'填充$data

您应该尝试 debug($this->request) 以查看使用 GET 或更好的方式传递数据的结果,使用 POST 并检查 $this->request->data (CakePHP 2) 或 $this->data ( CakePHP 1.3)

于 2012-06-08T15:29:37.757 回答