Commit: 714b27179d015efc542690357cb360cd807e3b5b

Author: Joël Perras | Date: 2010-05-11 12:10:08 -0400
Updating CollectionsController to protect against non-existing document lookups.
diff --git a/controllers/CollectionsController.php b/controllers/CollectionsController.php index 4df414d..b0ea958 100644 --- a/controllers/CollectionsController.php +++ b/controllers/CollectionsController.php @@ -39,7 +39,7 @@ class CollectionsController extends \lithium\action\Controller { } public function edit() { - $path = $this->request->args; + $path = $this->request->params['args']; $_id = array_shift($path); $item = $document = Collection::first(array( @@ -47,16 +47,18 @@ class CollectionsController extends \lithium\action\Controller { 'conditions' => compact('_id') )); - foreach (array_slice($path, 0, -1) as $key) { - $item =& $item[$key]; - } - $key = end($this->request->args); + if ($item) { + foreach (array_slice($path, 0, -1) as $key) { + $item =& $item[$key]; + } + $key = end($this->request->params['args']); - if ($item->{$key} == $this->request->data['old']) { - $item->{$key} = $this->request->data['data']; - $document->save(); - $this->render(array('text' => $this->request->data['data'])); - return; + if ($item->{$key} == $this->request->data['old']) { + $item->{$key} = $this->request->data['data']; + $document->save(); + $this->render(array('text' => $this->request->data['data'])); + return; + } } $this->render(array('text' => $this->request->data['old'])); }