Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- use Model\Status;
- class Controller_Statuses extends Controller_Template{
- public function action_index()
- {
- $data['statuses'] = Status::find_all();
- $this->template->title = "Statuses";
- $this->template->content = View::forge('statuses/index', $data);
- }
- public function action_view($id = null)
- {
- $data['status'] = Status::find_one_by_id($id);
- $this->template->title = "Status";
- $this->template->content = View::forge('statuses/view', $data);
- }
- public function action_create($id = null)
- {
- if (Input::method() == 'POST')
- {
- $status = Status::forge(array(
- 'content' => Input::post('content'),
- 'category_id' => Input::post('category_id'),
- ));
- if ($status and $status->save())
- {
- Session::set_flash('notice', 'Added status #' . $status->id . '.');
- Response::redirect('statuses');
- }
- else
- {
- Session::set_flash('notice', 'Could not save status.');
- }
- }
- $this->template->title = "Statuses";
- $this->template->content = View::forge('statuses/create');
- }
- public function action_edit($id = null)
- {
- $status = Status::find_one_by_id($id);
- if (Input::method() == 'POST')
- {
- $status->content = Input::post('content');
- $status->category_id = Input::post('category_id');
- if ($status->save())
- {
- Session::set_flash('notice', 'Updated status #' . $id);
- Response::redirect('statuses');
- }
- else
- {
- Session::set_flash('notice', 'Could not update status #' . $id);
- }
- }
- else
- {
- $this->template->set_global('status', $status, false);
- }
- $this->template->title = "Statuses";
- $this->template->content = View::forge('statuses/edit');
- }
- public function action_delete($id = null)
- {
- if ($status = Status::find_one_by_id($id))
- {
- $status->delete();
- Session::set_flash('notice', 'Deleted status #' . $id);
- }
- else
- {
- Session::set_flash('notice', 'Could not delete status #' . $id);
- }
- Response::redirect('statuses');
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement