本文介绍了cakephp:编辑播放器后转到上一页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的页面中有玩家.例如,我在第13页.在这里,我单击编辑功能来编辑播放器.现在,在编辑之后,我想回到第13页,但它停留在编辑页面上.
I have players in pages. I'm for instance on page 13. Here I click on the edit function to edit a player. Now after the edit I want to get back to that page 13 but It stays at the edit page.
编辑操作:
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(array('post', 'put')) = TRUE
部分)中使用该存储的值.
You can save the referring page in the else
section of the if/else
structure of the edit function. Then use that stored value in the if
(i.e., $this->request->is(array('post', 'put')) = TRUE
section.
因此您的代码应类似于:
So your code would look something like:
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());
}
}
这篇关于cakephp:编辑播放器后转到上一页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!