public static function exceptionHandler(\Exception $exception) { $template = new Template('error.twig'); $template->title = 'Error'; $template->alert('danger', $exception->getMessage()); $template->e = $exception; $template->render(true); }
public function index(Request $request, Response $response, array $args) { $template = new Template('home.twig'); // Get a list of tags to show. $tagsSql = "SELECT tags.id, tags.title, count(*) AS item_count " . " FROM tags JOIN item_tags ON tags.id=item_tags.tag " . " GROUP BY tags.id"; $params = []; if (isset($args['id'])) { $tagsSql .= " WHERE id = :id"; $params['id'] = $args['id']; } $template->tags = $this->db->query($tagsSql, $params); // Get the Items with the currently-selected tags. $sql = "SELECT items.id FROM items " . " JOIN groups ON groups.id = items.read_group " . " LIMIT 20"; $params = []; $items = $this->db->query($sql, $params, '\\App\\Item'); $template->items = $items; $template->title = 'Home'; // Return. $response->setContent($template->render()); return $response; }
public function remind(Request $request, Response $response, array $args) { $name = $request->get('name'); if ($request->get('login')) { return new RedirectResponse($this->config->baseUrl() . '/login?name=' . $name); } $config = new Config(); $user = new User($this->db); $user->loadByName($name); $template = new Template('remind_email.twig'); if (!empty($user->getEmail())) { $template->user = $user; $template->token = $user->getReminder(); $message = \Swift_Message::newInstance()->setSubject('Password reminder')->setFrom(array($config->siteEmail() => $config->siteTitle()))->setTo(array($user->getEmail() => $user->getName()))->setBody($template->render(), 'text/html'); $this->email($message); } else { // Pause for a moment, so it's not so obvious which users' names are resulting in mail being sent. sleep(5); } $template->alert('success', 'Please check your email', true); return new RedirectResponse($this->config->baseUrl() . '/remind?name=' . $name); }
<?php use App\TopicData; use App\Template; if (isset($_POST['id']) && !empty($_POST['id'])) { $data = new TopicData(); if ($data->update($_POST)) { header('Location: /index.php'); exit; } else { echo 'An error occurred'; exit; } } if (!isset($_GET['id']) || empty($_GET['id'])) { echo 'You did not pass in an ID.'; exit; } $data = new TopicData(); $topic = $data->getTopic($_GET['id']); if ($topic === false) { echo 'Topic not found!'; exit; } $template = new Template('../views/base.phtml'); $template->render('../views/index/edit.phtml', ['topic' => $topic]);
public function profile(Request $request, Response $response, array $args) { $template = new \App\Template('profile.twig'); $template->title = 'Profile'; $response->setContent($template->render()); return $response; }