CakePHP:重定向无法正常工作

时间:2016-12-08 13:30:03

标签: php cakephp

所以我在cakephp3中有一个项目和一个具有多个功能的控制器,除了一个之外,所有这些都使用function(err, todo) { console.log(todo); if (!err) return response.send(todo); // or send whatever or respnose.end() console.log('bbb'); response.send(err); }); 非常好。

我的UserController也有这个问题,它有一个登录和注册方法,当我在注册后尝试重定向时,它不起作用。

我不知道为什么只有这些特殊功能不起作用。我尝试过其他重定向方法,例如return $this->redirect('/');

代码:

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

任何帮助表示感谢。

修改

使用:

解决它
$values = get_object_vars(json_decode($response->body));

        if (isset($values['error_description'])) {
          $this->Flash->error(__($values['error_description']));
        } else {
            $response = $http->post($this->Api->getExecutionCreationLocation(), [
                'experiment_id' => $values['id'],
                'computational_model_id' => '2',
                'inputs' => json_encode($inputs)
            ],[
              'headers' => [
                'Content-Type' => 'application/x-www-form-urlencoded',
                'Authorization' => "Bearer ".$this->OAuth->getToken(),
              ]
            ]);

            $values = get_object_vars(json_decode($response->body));

            if (isset($values['error_description'])) {
                $this->Flash->error(__($values['error_description']));
            } else {  
              $this->Flash->error(__("Experiment created."));
              return $this->redirect('/');
            } 
    }

我不知道这是否正确,但它正在发挥作用。

0 个答案:

没有答案
相关问题