/** * Display the addList page of the application. * * @param Pluf_HTTP_Request Request object * @param array Matches against the regex of the dispatcher * @return Pluf_HTTP_Response or can throw Exception */ public function addList($request, $match) { // The workflow of the addition of an item is simple // If the request of GET method a form is displayed // If it is a POST method, the form is submitted and the // content is proceeded to create the new list. // We create a Todo_List item as we are creating one here $list = new Todo_List(); if ($request->method == 'POST') { // We create the form bounded to the data submitted. $form = new Todo_Form_List($request->POST); if ($form->isValid()) { // If no errors, we can save the Todo_List from the data $list->setFromFormData($form->cleaned_data); $list->create(); // We redirect the user to the page of the Todo_List $url = Pluf_HTTP_URL_urlForView('Todo_Views::viewList', array($list->id)); return new Pluf_HTTP_Response_Redirect($url); } } else { $form = new Todo_Form_List(); } return Pluf_Shortcuts_RenderToResponse('todo/list/add.html', array('page_title' => 'Add a Todo List', 'form' => $form)); }