Advertisement
Guest User

Untitled

a guest
Dec 11th, 2011
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.02 KB | None | 0 0
  1. <?php
  2. use Model\Status;
  3.  
  4. class Controller_Statuses extends Controller_Template{
  5.  
  6.     public function action_index()
  7.     {
  8.         $data['statuses'] = Status::find_all();
  9.         $this->template->title = "Statuses";
  10.         $this->template->content = View::forge('statuses/index', $data);
  11.  
  12.     }
  13.  
  14.     public function action_view($id = null)
  15.     {
  16.         $data['status'] = Status::find_one_by_id($id);
  17.  
  18.         $this->template->title = "Status";
  19.         $this->template->content = View::forge('statuses/view', $data);
  20.  
  21.     }
  22.  
  23.     public function action_create($id = null)
  24.     {
  25.         if (Input::method() == 'POST')
  26.         {
  27.             $status = Status::forge(array(
  28.                 'content' => Input::post('content'),
  29.                 'category_id' => Input::post('category_id'),
  30.             ));
  31.  
  32.             if ($status and $status->save())
  33.             {
  34.                 Session::set_flash('notice', 'Added status #' . $status->id . '.');
  35.  
  36.                 Response::redirect('statuses');
  37.             }
  38.  
  39.             else
  40.             {
  41.                 Session::set_flash('notice', 'Could not save status.');
  42.             }
  43.         }
  44.  
  45.         $this->template->title = "Statuses";
  46.         $this->template->content = View::forge('statuses/create');
  47.  
  48.     }
  49.  
  50.     public function action_edit($id = null)
  51.     {
  52.         $status = Status::find_one_by_id($id);
  53.  
  54.         if (Input::method() == 'POST')
  55.         {
  56.             $status->content = Input::post('content');
  57.             $status->category_id = Input::post('category_id');
  58.  
  59.             if ($status->save())
  60.             {
  61.                 Session::set_flash('notice', 'Updated status #' . $id);
  62.  
  63.                 Response::redirect('statuses');
  64.             }
  65.  
  66.             else
  67.             {
  68.                 Session::set_flash('notice', 'Could not update status #' . $id);
  69.             }
  70.         }
  71.  
  72.         else
  73.         {
  74.             $this->template->set_global('status', $status, false);
  75.         }
  76.  
  77.         $this->template->title = "Statuses";
  78.         $this->template->content = View::forge('statuses/edit');
  79.  
  80.     }
  81.  
  82.     public function action_delete($id = null)
  83.     {
  84.         if ($status = Status::find_one_by_id($id))
  85.         {
  86.             $status->delete();
  87.  
  88.             Session::set_flash('notice', 'Deleted status #' . $id);
  89.         }
  90.  
  91.         else
  92.         {
  93.             Session::set_flash('notice', 'Could not delete status #' . $id);
  94.         }
  95.  
  96.         Response::redirect('statuses');
  97.  
  98.     }
  99.  
  100.  
  101. }
  102.  
  103.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement