Skip to content
Permalink
Browse files

Changing Scaffold to use exceptions to indicate error states.

Starting to convert record deletion to POST only.
  • Loading branch information...
markstory committed Dec 12, 2010
1 parent 661195d commit 495061537fd1e776fe3436f89ba28a87004130e4
Showing with 14 additions and 13 deletions.
  1. +14 −13 cake/libs/controller/scaffold.php
@@ -172,15 +172,14 @@ protected function _output() {
*/
protected function _scaffoldView(CakeRequest $request) {
if ($this->controller->_beforeScaffold('view')) {
$message = __("No id set for %s::view()", Inflector::humanize($this->modelKey));
if (isset($request->params['pass'][0])) {
$this->ScaffoldModel->id = $request->params['pass'][0];
} else {
return $this->_sendMessage($message);
}
if (!$this->ScaffoldModel->exists()) {
throw new NotFoundException(__('Invalid %s', Inflector::humanize($this->modelKey)));
}
$this->ScaffoldModel->recursive = 1;
$this->controller->request->data = $this->controller->data = $this->ScaffoldModel->read();
$this->controller->request->data = $this->ScaffoldModel->read();
$this->controller->set(
Inflector::variable($this->controller->modelClass), $this->request->data
);
@@ -245,10 +244,8 @@ protected function _scaffoldSave(CakeRequest $request, $action = 'edit') {
if (isset($request->params['pass'][0])) {
$this->ScaffoldModel->id = $request['pass'][0];
}
if (!$this->ScaffoldModel->exists()) {
$message = __("Invalid id for %s::edit()", Inflector::humanize($this->modelKey));
return $this->_sendMessage($message);
throw new NotFoundException(__('Invalid %s', Inflector::humanize($this->modelKey)));
}
}
@@ -308,14 +305,18 @@ protected function _scaffoldSave(CakeRequest $request, $action = 'edit') {
*/
protected function _scaffoldDelete(CakeRequest $request) {
if ($this->controller->_beforeScaffold('delete')) {
$message = __("No id set for %s::delete()", Inflector::humanize($this->modelKey));
if (!$request->is('post')) {
throw new MethodNotAllowedException();
}
$id = false;
if (isset($request->params['pass'][0])) {
$id = $request->params['pass'][0];
} else {
return $this->_sendMessage($message);
}
if ($this->ScaffoldModel->delete($id)) {
$this->ScaffoldModel->id = $id;
if (!$this->ScaffoldModel->exists()) {
throw new NotFoundException(__('Invalid %s', Inflector::humanize($this->modelClass)));
}
if ($this->ScaffoldModel->delete()) {
$message = __('The %1$s with id: %2$d has been deleted.', Inflector::humanize($this->modelClass), $id);
return $this->_sendMessage($message);
} else {

0 comments on commit 4950615

Please sign in to comment.
You can’t perform that action at this time.