function get($modelClass, $id) { $model = modelFind($modelClass, 'id', $id); if (!$model) { $this->show_error("{$modelClass} not found"); } return $model; }
function do_login() { if (isGet()) { $this->render(); } else { if (isPost()) { $user = modelFind('User', 'email', param('email')); if ($user->isPassword(param('password'))) { $this->session->set_userdata('user', $user->id); $this->returnTo(url_to($user)); } else { $this->flash('Login failed - please try again'); redirect(url_to($user, 'login')); } } } }
function applyForm($entry, $owner = null) { $fields = explode(' ', "type name description email private_email url phone address password"); foreach ($fields as $field) { $entry->{$field} = trim(param($field, $entry->{$field})); } if ($this->currentUser->is_admin) { if (is_numeric(param('owner_id'))) { $new_owner = modelFind('User', 'id', param('owner_id')); if ($new_owner->id) { $owner = $new_owner; } } } if (isSpam($entry->name, $entry->email, $entry->description)) { $this->template->write('content', 'Yuck, that really didn\'t taste very good!'); $this->template->render(); die; } $entry->save($owner); // Do this after entry save since we need to know the entry ID if (isset($_FILES['image'])) { if ($_FILES['image']['size'] > 0 && $_FILES['image']['size'] < 1000000) { $entry->setImage($_FILES['image']['tmp_name']); $entry->save(null, false); } } }