Dear masters,
I want to created a template named random.phtml to show some random results which can be included to other templates(index.phtml, subpage.phtml), the following code requires access to domain.com/random/ to get the results, how can i create the dynamic page without post/get queries?
at route.php
// random results
$app->get('/random/', function ($request, $response) {
$sth = $this->db->prepare("SELECT id,images FROM table ORDER BY RAND() LIMIT 10");
$sth->execute();
$todos = $sth->fetchAll();
return $this->renderer->render($response, 'random.phtml', array(
'results' => $todos,
));
});
random.phtml
<?php
if (!empty($results)) {
echo '<ul>';
foreach ($results as $result) {
echo '<li>'.$result['id'].' '.$result['images'].'</li>';
}
echo '</ul>';
}
?>