Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Controller_Posts extends Controller_Base
- {
- public function action_index()
- {
- $view = View::forge('posts/index');
- $pagination = Model_Post::count(array(
- 'where' => array(
- array('active', 1),
- ),
- ));
- $config = array(
- 'pagination_url' => 'posts/index/',
- 'total_items' => $pagination,
- 'per_page' => 2,
- 'uri_segment' => 3,
- );
- Paginationbootstrap::set_config($config);
- $view->posts = Model_Post::find('all', array(
- 'where' => array(
- array('active', 1),
- ),
- 'order_by' => array('created_at' => 'desc'),
- 'limit' => Paginationbootstrap::$per_page,
- 'offset' => Paginationbootstrap::$offset,
- ));
- $view->set('pagination', Paginationbootstrap::create_links(), false);
- $this->template->title = "Blog";
- $this->template->content = $view;
- }
- public function action_view($slug)
- {
- $view = View::forge('posts/view');
- $view->set('post', Model_Post::query()->where('slug', $slug)->related('comments')->order_by('comments.created_at', 'desc')->get_one(), false);
- $this->template->title = $view->post->title;
- $this->template->date = $view->post->created_at;
- $this->template->content = $view;
- }
- public function action_comment($slug)
- {
- if (Input::method() == 'POST')
- {
- $val = Model_Comment::validate('create');
- if ($val->run())
- {
- $comment = Model_Comment::forge(array(
- 'pseudo' => Input::post('pseudo'),
- 'email' => Input::post('email'),
- 'message' => Input::post('message'),
- 'post_id' => Input::post('post_id'),
- 'user_id' => Input::post('user_id'),
- ));
- if ($comment and $comment->save())
- {
- Session::set_flash('success', 'Votre commentaire a bien été envoyé.');
- Response::redirect('posts/view/'.$slug);
- }
- else
- {
- Session::set_flash('error', 'Impossible d\'envoyer votre commentaire.');
- }
- }
- else
- {
- Session::set_flash('error', $val->show_errors());
- }
- }
- Response::redirect('posts/view/'.$slug);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement