$c['contacts'] = $contacts; $c['field_types'] = $field_types; $app->render('pages/editform.html', $c); })->name('getFormEdit'); // /form/edit/:id/contacts/add controller // Contacts add controller // When accessing /form/edit/:id/contacts/add via GET, // a new contact is created for that forms $app->get('/form/edit/:id/contacts/add', function ($id) use($app) { $c = array(); // We have to create a new contact and default it $contact = new models\Contact(); $contact->contact_name = 'New contact'; $contact->contact_email = '*****@*****.**'; $contact->form_id = $id; $contact->save(); $app->redirect($app->urlFor('getFormEdit', array('id' => $id))); })->name('getFormContactAdd'); // /form/edit/:id_form/contacts/remove/:id_contact controller // Contacts remove controller // When accessing /form/edit/:id/contacts/add via GET, // a new contact is removed from the form // TODO: check integrity in the relationship $app->get('/form/edit/:id_form/contacts/remove/:id_contact', function ($id_form, $id_contact) use($app) { $c = array(); // First we have to find the contact $contact = models\Contact::find($id_contact); $contact->delete(); $app->redirect($app->urlFor('getFormEdit', array('id' => $id_form))); })->name('getFormContactRemove'); // /form/new controller