【发布时间】:2014-06-09 17:14:25
【问题描述】:
我有一个从我的应用程序的画廊中删除图像的操作。当用户单击“删除”按钮时,图像被删除并显示“成功”消息,但删除的图像仍在图像列表中,一旦我按刷新它就消失了。
如何在用户按下删除按钮后立即使该图像消失?
我已经尝试过使用$this->redirect('/Admin/Dashboard/Gallery/Delete');,但这不允许显示“成功”消息。
我使用的是 CakePHP 2.4.4。
控制器
public function deleteImages($id){
$this->set('title_for_layout', 'Apagar imagens');
$this->layout = 'admin';
$this->loadModel('GalleryImage');
$this->GalleryImage->id=$id;
$this->Paginator->settings = array(
'GalleryImage' => array(
'limit' => 20,
//'maxLimit' => 100,
'order' => array('GalleryImage.modified' => 'desc') // Por exemplo
)
);
$gallery_images=$this->Paginator->paginate('GalleryImage');
$this->set('gallery_images', $gallery_images);
if($this->request->is('post')){
if(!$this->GalleryImage->exists()){
throw new NotFoundException('Erro, esta fotografia não foi encontrada.', 'default', array('class'=>'alert flashMessageDanger alert-dismissable'));
}
$options = array('conditions' => array('GalleryImage.'.$this->GalleryImage->primaryKey=>$id));
$gallery_image_delete = $this->GalleryImage->find('first', $options);
if(file_exists(WWW_ROOT."img/Gallery/" .$gallery_image_delete['GalleryImage']['name'])){
unlink(WWW_ROOT."img/Gallery/".$gallery_image_delete['GalleryImage']['name']);
$this->GalleryImage->delete();
$this->Session->setFlash('A Imagem foi excluída com sucesso.', 'default', array('class'=>'alert flashMessageSuccess alert-dismissable'));
$this->redirect('/Admin/Dashboard/Gallery/Delete');
}else{
$this->Session->setFlash('Erro, esta Imagem não existe.', 'default', array('class' => 'alert flashMessageDanger alert-dismissable'));
}
//$this->redirect('/Admin/Dashboard/Gallery/Delete');
}
}
【问题讨论】:
标签: cakephp cakephp-2.4