NoteController.php (2388B)
1 <?php 2 3 /** 4 * The note controller: Just an example of simple create, read, update and delete (CRUD) actions. 5 */ 6 class NoteController extends Controller 7 { 8 /** 9 * Construct this object by extending the basic Controller class 10 */ 11 public function __construct() 12 { 13 parent::__construct(); 14 15 // VERY IMPORTANT: All controllers/areas that should only be usable by logged-in users 16 // need this line! Otherwise not-logged in users could do actions. If all of your pages should only 17 // be usable by logged-in users: Put this line into libs/Controller->__construct 18 Auth::checkAuthentication(); 19 } 20 21 /** 22 * This method controls what happens when you move to /note/index in your app. 23 * Gets all notes (of the user). 24 */ 25 public function index() 26 { 27 $this->View->render('note/index', array( 28 'notes' => NoteModel::getAllNotes() 29 )); 30 } 31 32 /** 33 * This method controls what happens when you move to /dashboard/create in your app. 34 * Creates a new note. This is usually the target of form submit actions. 35 * POST request. 36 */ 37 public function create() 38 { 39 NoteModel::createNote(Request::post('note_text')); 40 Redirect::to('note'); 41 } 42 43 /** 44 * This method controls what happens when you move to /note/edit(/XX) in your app. 45 * Shows the current content of the note and an editing form. 46 * @param $note_id int id of the note 47 */ 48 public function edit($note_id) 49 { 50 $this->View->render('note/edit', array( 51 'note' => NoteModel::getNote($note_id) 52 )); 53 } 54 55 /** 56 * This method controls what happens when you move to /note/editSave in your app. 57 * Edits a note (performs the editing after form submit). 58 * POST request. 59 */ 60 public function editSave() 61 { 62 NoteModel::updateNote(Request::post('note_id'), Request::post('note_text')); 63 Redirect::to('note'); 64 } 65 66 /** 67 * This method controls what happens when you move to /note/delete(/XX) in your app. 68 * Deletes a note. In a real application a deletion via GET/URL is not recommended, but for demo purposes it's 69 * totally okay. 70 * @param int $note_id id of the note 71 */ 72 public function delete($note_id) 73 { 74 NoteModel::deleteNote($note_id); 75 Redirect::to('note'); 76 } 77 }