<?php
use Awesomite\Chariot\RouterInterface;
use Awesomite\Nano\Container\Container;
use Awesomite\Nano\Nano;
/*
* Creating nano app
*/
$app = new Nano();
/**
* Filling the container
*/
$app->getContainer()
->set('mysql', new MyMysqlConnection());
/*
* Enable error handler
*/
$app
->enableDebugMode()
->enableErrorHandling();
/*
* Register callbacks
*/
$app->get('/', function () {
return 'Welcome on my website';
});
$app->get('/hello-{{ name }}', function (string $name) {
return 'Hello ' . $name;
});
$app->get('/category-{{ category }}/item-{{ itemId :int }}', function (int $itemId, string $category) {
return sprintf('Item %d from category %s', $itemId, $category);
});
$app->get('/mysql', function (MyMysqlConnection $mysql) { // $mysql comes from container
$mysql->execute('MY QUERY...');
return 'OK';
});
/*
* Named routes
*/
$app->get(['/user-{{ name }}', 'userpage'], function (string $name) {
return 'Hello, ' . $name . '!';
});
$app->get('/menu', function (RouterInterface $router) {
return [
(string)$router->linkTo('userpage')->withParam('name', 'John'),
(string)$router->linkTo('userpage')->withParam('name', 'Jane'),
];
});
/*
* Voila!
*/
$app->run();-
Notifications
You must be signed in to change notification settings - Fork 0
License
awesomite/nano
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
About
No description, website, or topics provided.
Resources
License
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published