Skip to content

Commit

Permalink
Add Flash message and redirect in case delete fails
Browse files Browse the repository at this point in the history
  • Loading branch information
hakermania committed Jan 26, 2015
1 parent 747ba60 commit 10a4720
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
7 changes: 6 additions & 1 deletion en/tutorials-and-examples/blog/part-two.rst
Original file line number Diff line number Diff line change
Expand Up @@ -563,8 +563,13 @@ Next, let's make a way for users to delete posts. Start with a
$this->Session->setFlash(
__('The post with id: %s has been deleted.', h($id))
);
return $this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(
__('The post with id: %s could not be deleted.', h($id))
);
}

return $this->redirect(array('action' => 'index'));
}

This logic deletes the post specified by $id, and uses
Expand Down
11 changes: 9 additions & 2 deletions ja/tutorials-and-examples/blog/part-two.rst
Original file line number Diff line number Diff line change
Expand Up @@ -480,9 +480,16 @@ PostsControllerの ``delete()`` アクションを作るところから始めま
}

if ($this->Post->delete($id)) {
$this->Session->setFlash(__('The post with id: %s has been deleted.', h($id)));
return $this->redirect(array('action' => 'index'));
$this->Session->setFlash(
__('The post with id: %s has been deleted.', h($id))
);
} else {
$this->Session->setFlash(
__('The post with id: %s could not be deleted.', h($id))
);
}

return $this->redirect(array('action' => 'index'));
}

このロジックは、$idで指定された記事を削除し、
Expand Down
7 changes: 6 additions & 1 deletion zh/tutorials-and-examples/blog/part-two.rst
Original file line number Diff line number Diff line change
Expand Up @@ -494,8 +494,13 @@ edit 视图会是这样:
$this->Session->setFlash(
__('The post with id: %s has been deleted.', h($id))
);
return $this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(
__('The post with id: %s could not be deleted.', h($id))
);
}

return $this->redirect(array('action' => 'index'));
}

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

0 comments on commit 10a4720

Please sign in to comment.