PHP code example of warnstar / tin-core
1. Go to this page and download the library: Download warnstar/tin-core library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
warnstar / tin-core example snippets
// 实例化路由处理器对象
$r = new \Tin\Base\Router();
// 设置全局中间件
$r->addMiddleware(\app\middleware\TestMiddleware::class);
// 路由内设置中间件
$r->get('/mid2', \app\controllers\IndexController::class . '@index')->addMiddleware(\app\middleware\AbcMiddleware::class);
// 设置路由
$r->get('/users', \app\controllers\IndexController::class . '@index');
$r->get('/index/{id:\d+}', \app\controllers\IndexController::class . '@index');
// 设置路由组
$r->group("/test", function(\Tin\Base\Router $r){
$r->get('/mid', \app\controllers\TestController::class . '@mid');
});
$this->request->getHeaders();
$this->request->getHeader("key");
// query
$this->request->getQueryParams();
$this->request->getQueryParam("key");
// form or json
$this->request->getParsedBodyParam("key" , "default");
$this->request->getParsedBody();
$r = new \Tin\Router();
$r->get('/', \app\admin\controllers\IndexController::class . '@index');
$components['router'] = $r;
$components['server'] = \Tin\HttpServer::build();
(new \Tin($components))->run();