嗨,我在 Controller 中有这个方法
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 表单测试 Controller
$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')。 Controller 函数没有接收到数组
最佳答案
您的注册用户需要 1 个参数($data),因此 URL 应如下所示:
/foo/registeruser/bar
这会用'bar'填充$data
您应该尝试 debug($this->request) 以查看使用 GET 或更好的方式传递数据的结果,使用 POST 并查看 $this->request->data (CakePHP 2) 或 $this->数据(CakePHP 1.3)
关于cakephp - 使用数组测试 Controller Cakephp 2 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10948704/