I've written a base model class I can extend in order to save time writing redundant code and database queries.
Code: Select all
class user extends baseModel {
public function update($id, $data) {
try {
$data = $this->_filterIn($data);
$this->_validateCommon($data);
$this->_validateUpdate($id, $data);
return parent::update($id, $data);
} catch (Exception $e) {
$this->_setError($e->getMessage());
}
}
}
Now at the controller layer it would look something like this:
Code: Select all
class userController extends controllerBase {
public function updateAction() {
if (is_post()) {
$user = new user();
if ($user->update($id, $_POST)) {
// do something
} else {
// do something
}
}
include SOME_CONSTANT . 'pages/user/update.php';
}
}