dqrmkdu25623 2013-08-14 22:44
浏览 13

CakePHP没有重定向,没有显示错误

I'm having a bit of trouble getting a page to redirect after deleting some data. It previously worked, and I have since added a lot so I have no idea what's causing the issue.

Here's the function, generated through Baking. The strange part is the function works and properly deletes the record, but it just stays on the blank page.

public function delete($id = null) {
    $this->Visit->id = $id;
    if (!$this->Visit->exists()) {
        throw new NotFoundException(__('Invalid visit'));
    }
    $this->request->onlyAllow('post', 'delete');
    if ($this->Visit->delete()) {
        $this->Session->setFlash(__('Visit deleted'));
        $this->redirect(array('action' => 'index'));
    }
    $this->Session->setFlash(__('Visit was not deleted'));
    $this->redirect(array('action' => 'index'));
}

However, when I change it to just redirect upon the function call, it works. Something is up with the delete and I can't seem to figure out what's happening.

 public function delete($id = null) {
    $this->Visit->id = $id;
    if (!$this->Visit->exists()) {
        throw new NotFoundException(__('Invalid visit'));
    }

    $this->Session->setFlash(__('Visit deleted'));
    $this->redirect(array('action' => 'index'));

}

What can I look for? I don't have anything in my Models regarding redirects

  • 写回答

1条回答 默认 最新

  • dongre6073 2013-08-15 05:40
    关注

    I think you have to add the controller:

    // http://book.cakephp.org/2.0/en/controllers.html
    
    $this->redirect(array('controller' => '<YOUR CONTROLLER NAME>', 'action' => 'index'));
    

    You can alsy try this if you want to redirect to the referer page

    $this->redirect($this->referer());
    

    For future work: you say " just stays on the blank page". What is your debug level? If it's in dev-mode the redirects are not automated done, but there's a link continue to redirect (text might be similar, don't have in mind). And you can see if the target is reachable, e.g. does the controller actions exists.

    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么