cakephp:编辑播放器后转到上一页

cakephp:编辑播放器后转到上一页,php,cakephp,http-referer,referer,Php,Cakephp,Http Referer,Referer,我在页面上有播放器。例如,我在第13页。在这里,我点击编辑功能来编辑一个播放器。现在在编辑之后,我想回到第13页,但它停留在编辑页 编辑操作: public function admin_edit($id = null) { if (!$this->Player->exists($id)) { throw new NotFoundException(__('Invalid player')); } if ($this->request-&

我在页面上有播放器。例如,我在第13页。在这里,我点击编辑功能来编辑一个播放器。现在在编辑之后,我想回到第13页,但它停留在编辑页

编辑操作:

public function admin_edit($id = null) {
    if (!$this->Player->exists($id)) {
        throw new NotFoundException(__('Invalid player'));
    }
    if ($this->request->is(array('post', 'put'))) {
        $data = $this->request->data['Player'];
        if(!$data['player_image']['name']){
            unset($data['player_image']);
        }
        if ($this->Player->save($data)) {
            $this->Session->setFlash(__('The player has been saved.'));
            $this->redirect($this->referer());
        } else {
            $this->Session->setFlash(__('The player could not be saved. Please, try again.'));
        }
    } else {
        $options = array('conditions' => array('Player.' . $this->Player->primaryKey => $id));
        $this->request->data = $this->Player->find('first', $options);
    }
    $videos = $this->Player->Video->find('list');
    $this->set(compact('videos'));
}
查看操作:

public function admin_view($id = null) {
    if (!$this->Player->exists($id)) {
        throw new NotFoundException(__('Invalid player'));
    }
    $options = array('conditions' => array('Player.' . $this->Player->primaryKey => $id));
    $this->set('player', $this->Player->find('first', $options));
}

您可以在编辑功能的
if/else
结构的
else
部分保存引用页面。然后使用
中存储的值if
(即
$this->request->is(数组('post','put'))=TRUE
部分

因此,您的代码看起来像:

public function admin_edit($id = null) {
  if ($this->request->is(array('post', 'put'))) {

    /* your other code */

    $sendback = $this->Session->read('referer');
    $this->Session->delete('referer');
    $this->redirect($sendback);

  } else {

    /* your other code */

    $this->Session->write('referer', $this->referer());
  }
}

您不需要返回重定向,您是否尝试过
$this->redirect($this->referer())
?或者调试
$this->referer
,可能它来自同一个编辑页面,这就是它停留在那里的原因(从您提供的代码中我不知道)你给我的两个选项给了我同样的结果:/你告诉我,如果你在
admin\u edit
中调试
$this->referer()
,你会得到
admin/controller/view/13
?我真诚地怀疑,除非保存失败。我会得到admin/players/edit/58