Пример #1
0
 *
 */
// 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();
Пример #2
0
});
$app->router->add('source', function () use($app) {
    $app->theme->addStylesheet('css/source.css');
    $app->theme->setTitle("Source code");
    $source = new \Me\Source\CSource(['secure_dir' => '..', 'base_dir' => '..', 'add_ignore' => ['.htaccess']]);
    $app->views->add('me/source', ['content' => $source->View()]);
});
$app->router->add('dice', function () use($app) {
    $app->theme->setTitle('Spela tärning');
    $app->theme->addStylesheet('css/dice.css');
    $die = new \Mos\Dice\CDice();
    $results = null;
    $total = null;
    $roll = null;
    if (isset($_GET['roll']) && $_GET['roll'] > 0 && $_GET['roll'] < 7) {
        $die->roll($_GET['roll']);
        $roll = filter_var($_GET['roll'], FILTER_SANITIZE_NUMBER_INT);
        $results = $die->getResults();
        $total = $die->getTotal();
    }
    $app->views->add('dice/index', ['roll' => $roll, 'results' => $results, 'total' => $total]);
});
$app->router->add('presentation/kmom01', function () use($app) {
    $app->theme->setVariable('title', "Kmom01");
    $content = $app->fileContent->get('presentation/kmom01.md');
    $content = $app->textFilter->doFilter($content, 'shortcode, markdown, nl2br');
    $byline = $app->fileContent->get('byline.md');
    $byline = $app->textFilter->doFilter($byline, 'shortcode, markdown');
    $app->views->add('me/page', ['content' => $content, 'byline' => $byline]);
});
// Render the response using theme engine.