Advertisement
hombretao

Blog.php

Feb 19th, 2014
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.75 KB | None | 0 0
  1. <?php defined('SYSPATH') or die('No direct script access.');
  2.  
  3. class Controller_Blog extends Controller_Template {
  4.  
  5.     public function action_index()  {
  6.  
  7.         $posts = ORM::factory('Post')->find_all();
  8.         $view = View::factory('blog/index')
  9.             ->bind('posts', $posts);
  10.         $this->template->content = $view;
  11.     }
  12.  
  13.     public function action_new() {
  14.  
  15.         if($_POST) {
  16.        
  17.             try {
  18.  
  19.                 $post = ORM::factory('Post');
  20.                 $post->author = $_POST['author'];
  21.                 $post->body = $_POST['body'];
  22.                 $post->save();
  23.                 $this->redirect('/');  
  24.             } catch (ORM_Validation_Exception $e) {
  25.  
  26.                 $errors = $e->errors('model');
  27.             }
  28.         }
  29.        
  30.         $view = View::factory('blog/new')
  31.             ->bind('errors', $errors)
  32.             ->bind('values', $_POST);
  33.         $this->template->content = $view;
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement