Created
March 18, 2011 11:37
-
-
Save lukemorton/875923 to your computer and use it in GitHub Desktop.
Validation without exceptions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php defined('SYSPATH') or die('No direct script access.'); | |
class Controller_Page extends Controller { | |
public function action_unpublish() | |
{ | |
$validation = Model_Page::unpublish($this->request->param('id'), $this->user); | |
if ($errors = $validation->errors()) | |
{ | |
$this->response->body( | |
Debug::dump($errors) | |
); | |
} | |
// On success redirect elsewhere | |
$this->request->redirect( | |
Route::get('page')->uri() | |
); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php defined('SYSPATH') or die('No direct script access.'); | |
class Model_Page extends ORM { | |
public static function unpublish($id, $user) | |
{ | |
$page = ORM::factory('page', $id) | |
->values(array( | |
'status' => 2, | |
'last_edited_by' => $user->id, | |
)); | |
$validation = $page->validation(); | |
if ($validation->check()) | |
{ | |
$page->save(); | |
} | |
return $validation; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment