public function loginAction() { $request = $this->app->request; $resp = new Response(); $errors = array(); if ($request->is('POST')) { $login = $request->getPostParam('login'); $pass = $request->getPostParam('pass'); if (!$login) { $errors['login'] = '******'; } if (!$pass) { $errors['pass'] = '******'; } if (!$errors) { if ($this->app->user->login($login, $pass)) { $resp->redirect($this->app->router->path('home')); return $resp; } else { $errors[] = 'Логин или пароль неверен'; } } $resp->setTplVars(array('values' => array('login' => $login, 'pass' => $pass))); } $resp->setTplVars(array('errors' => $errors)); $resp->setTemplate('login.html'); return $resp; }
public function createAction() { $request = $this->app->request; $resp = new Response(); $errors = array(); $title = $request->getPostParam('title'); $content = $request->getPostParam('content'); if (!$title) { $errors['title'] = 'Введите заголовок'; } if (!$content) { $errors['content'] = 'Введите текст'; } if (!$errors) { $post = new Post(array('user_id' => $this->app->user->getId(), 'title' => $title, 'content' => $content)); if ($id = $post->save()) { $resp->redirect($this->app->router->path('post.show', array($id))); return $resp; } else { $errors[] = 'Не удалось добавить пост'; } } $resp->setTplVars(array('values' => array('title' => $title, 'content' => $content))); $resp->setTplVars(array('errors' => $errors)); $resp->setTemplate('new_post.html'); return $resp; }