提交后的Cakephp重定向
我正在用Cakephp开发一个应用程序,在现有主题中找不到我的答案 我有一个主菜单,其中包含几个操作(编辑/删除/添加),即管理套接字。当我编辑套接字并提交更新时,套接字已正确更新,但主菜单上的重定向无效。URL保持不变。 例如,我编辑id为2的套接字。应用程序转到'/my/app/sockets/edit/2'。更新和提交后,应用程序应该重定向到“/my/app/sockets/index”,但它不起作用 下面,你可以看到我的代码。 socketscocontroller.php:提交后的Cakephp重定向,php,cakephp,redirect,caching,url-redirection,Php,Cakephp,Redirect,Caching,Url Redirection,我正在用Cakephp开发一个应用程序,在现有主题中找不到我的答案 我有一个主菜单,其中包含几个操作(编辑/删除/添加),即管理套接字。当我编辑套接字并提交更新时,套接字已正确更新,但主菜单上的重定向无效。URL保持不变。 例如,我编辑id为2的套接字。应用程序转到'/my/app/sockets/edit/2'。更新和提交后,应用程序应该重定向到“/my/app/sockets/index”,但它不起作用 下面,你可以看到我的代码。 socketscocontroller.php: publi
public function index($searchCloset = null) {
$this->Paginator->settings = $this->paginate;
if($searchCloset != null) {
$sockets = $this->paginate('Socket', array(
'Closet.name LIKE' => $searchCloset
));
}
else{
$sockets = $this->paginate('Socket');
$searchCloset = '' ;
}
$this->set('sockets',$sockets);
$this->set('closets',$this->Socket->Closet->find('all'));
$this->set('searchCloset',$searchCloset);
}
public function edit($id = null){
// Bad socket management
if (!$id) {
throw new NotFoundException(__('Invalid socket'));
}
$socket = $this->Socket->findByid_socket($id);
if (!$socket) {
throw new NotFoundException(__('Invalid socket'));
}
// if there's a submit
if ($this->request->is(array('post'))) {
$this->Socket->id = $id;
if ($this->Socket->save($this->request->data)) {
// update 'lastchange' column
if($this->updateSocketStatus($this->Socket->id)){
$this->Session->setFlash(__('Your socket has been updated.'));
}
else {
$this->Session->setFlash(__('Unable to create history.'));
}
}
else {
$this->Session->setFlash(__('Unable to update your socket.'));
}
return $this->redirect(array('controller' => 'sockets','action' => 'index'));
}
// send all informations about the socket to the view
$this->set('socket',$socket);
// send closets list to the view (select menu)
$this->set('closets',$this->Socket->Closet->find('list',array(
'fields' => array('Closet.id_closet','Closet.name')
)));
}
edit.ctp:
<h2>Edit socket</h2>
<div><?php
echo $this->Form->create('Socket');
echo $this->Form->input('Socket.name', array(
'label' => 'Socket name :',
'default' => $socket['Socket']['name']
));
echo $this->Form->input('Socket.location', array(
'label' => 'Location :',
'default' => $socket['Socket']['location']
));
echo $this->Form->input('Socket.comment', array(
'label' => 'Comment :',
'default' => $socket['Socket']['comment']
));
echo $this->Form->input('Socket.closet_id',array(
'type' => 'select',
'label' => 'Closet :',
'options' => $closets,
'default' => $socket['Closet']['id_closet']
));
echo $this->Form->end('Save socket');
echo $this->Form->postButton(
'Back',
array('controller' => 'sockets','action' => 'index'),
array(
'id' => 'back_button',
'class' => 'ui-btn ui-btn-inline ui-icon-back ui-btn-icon-left'
)
);
?></div>
编辑套接字
我已经搜索过了,可能是缓存问题。
提前感谢。您的请求检查语句是否被省略,因为
is()
方法根据接受字符串类型的参数
所以你应该换行:
if ($this->request->is(array('post'))) { ... }
进入:
你能强迫我吗
$this->redirect($this->referer());
请试着评论一下@Alawanegaine你能把
放到死里吗()
在每个if语句中使用不同的消息来检查请求是如何执行的?它当然可以工作,但它将我重定向到同一页(逻辑)。我的参考是/my/app/sockets/edit/2,我想进入“/my/app/sockets/index”!尝试$this->redirect(('action'=>'index');
$this->redirect($this->referer());