Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php defined('SYSPATH') or die('No direct script access.');
- class Controller_Blog extends Controller_Template {
- public function action_index() {
- $posts = ORM::factory('Post')->find_all();
- $view = View::factory('blog/index')
- ->bind('posts', $posts);
- $this->template->content = $view;
- }
- public function action_new() {
- if($_POST) {
- try {
- $post = ORM::factory('Post');
- $post->author = $_POST['author'];
- $post->body = $_POST['body'];
- $post->save();
- $this->redirect('/');
- } catch (ORM_Validation_Exception $e) {
- $errors = $e->errors('model');
- }
- }
- $view = View::factory('blog/new')
- ->bind('errors', $errors)
- ->bind('values', $_POST);
- $this->template->content = $view;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement