$l .= '<li><a href="/vacation/' . $app->escape($loc->area) . '/' . $app->escape($loc->slug) . '/">' . $app->escape($loc->title) . '</a></li> '; } return Page::display('Destinations found: <ul>' . $l . '</ul>'); }); // ... definitions $app->get('/vacation/{cont}/', function (App $app, $cont) { $locs = Location::where('area', $cont)->get(); $l = 'Destinations in this area: '; foreach ($locs as $loc) { $l .= '<li><a href="/vacation/' . $app->escape($loc->area) . '/' . $app->escape($loc->slug) . '/">' . $app->escape($loc->title) . '</a></li> '; } return Page::display('Destinations in this area: <ul>' . $l . '</ul> '); }); // ... definitions $app->get('/vacation/{cont}/{slug}/', function (App $app, $cont, $slug) { $loc = Location::where('slug', $slug)->where('area', $cont)->first(); $out = 'No such area found.'; if (null !== $loc) { assert((bool) $loc->title); $d = new DOMDocument(); $mock = new DOMDocument(); $d->loadHTML(file_get_contents(WWW . 'vacation/' . $cont . '/' . $slug . '.html')); $body = $d->getElementsByTagName('body')->item(0); foreach ($body->childNodes as $child) { $mock->appendChild($mock->importNode($child, true)); } $out = $mock->saveHTML(); } return Page::display(Page::additions() . $out); }); $app->run();