Skip to content

Commit 10a4720

Browse files
author
hakermania
committed
Add Flash message and redirect in case delete fails
1 parent 747ba60 commit 10a4720

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

en/tutorials-and-examples/blog/part-two.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,8 +563,13 @@ Next, let's make a way for users to delete posts. Start with a
563563
$this->Session->setFlash(
564564
__('The post with id: %s has been deleted.', h($id))
565565
);
566-
return $this->redirect(array('action' => 'index'));
566+
} else {
567+
$this->Session->setFlash(
568+
__('The post with id: %s could not be deleted.', h($id))
569+
);
567570
}
571+
572+
return $this->redirect(array('action' => 'index'));
568573
}
569574

570575
This logic deletes the post specified by $id, and uses

ja/tutorials-and-examples/blog/part-two.rst

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -480,9 +480,16 @@ PostsControllerの ``delete()`` アクションを作るところから始めま
480480
}
481481

482482
if ($this->Post->delete($id)) {
483-
$this->Session->setFlash(__('The post with id: %s has been deleted.', h($id)));
484-
return $this->redirect(array('action' => 'index'));
483+
$this->Session->setFlash(
484+
__('The post with id: %s has been deleted.', h($id))
485+
);
486+
} else {
487+
$this->Session->setFlash(
488+
__('The post with id: %s could not be deleted.', h($id))
489+
);
485490
}
491+
492+
return $this->redirect(array('action' => 'index'));
486493
}
487494

488495
このロジックは、$idで指定された記事を削除し、

zh/tutorials-and-examples/blog/part-two.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,8 +494,13 @@ edit 视图会是这样:
494494
$this->Session->setFlash(
495495
__('The post with id: %s has been deleted.', h($id))
496496
);
497-
return $this->redirect(array('action' => 'index'));
497+
} else {
498+
$this->Session->setFlash(
499+
__('The post with id: %s could not be deleted.', h($id))
500+
);
498501
}
502+
503+
return $this->redirect(array('action' => 'index'));
499504
}
500505

501506
这个逻辑删除 `$id` 指定的文章(*post*),然后使用 ``$this->Session->setFlash()``,

0 commit comments

Comments
 (0)