The following files exists in this folder. Click to view.
dice_app.php1 lines ASCII Unix (LF) <?php
/**
* This is a Anax frontcontroller.
*
*/
// Get environment & autoloader.
require __DIR__.'/config_with_app.php';
// Add extra assets
$app->theme->addStylesheet('css/dice.css');
// Home route
$app->router->add('', function() use ($app) {
$app->views->add('welcome/index');
$app->theme->setTitle("Welcome to Anax");
});
// Route to show welcome to dice
$app->router->add('dice', function() use ($app) {
$app->views->add('dice/index');
$app->theme->setTitle("Roll a dice");
});
// Route to roll dice and show results
$app->router->add('dice/roll', function() use ($app) {
// Check how many rolls to do
$roll = $app->request->getGet('roll', 1);
$app->validate->check($roll, ['int', 'range' => [1, 100]])
or die("Roll out of bounds");
// Make roll and prepare reply
$dice = new \Mos\Dice\CDice();
$dice->roll($roll);
$app->views->add('dice/index', [
'roll' => $dice->getNumOfRolls(),
'results' => $dice->getResults(),
'total' => $dice->getTotal(),
]);
$app->theme->setTitle("Rolled a dice");
});
// Check for matching routes and dispatch to controller/handler of route
$app->router->handle();
// Render the page
$app->theme->render();