swoole web project

Maintainers

Details

github.com/warnstar/tin

Source

Issues

Installs: 3

Dependents: 0

Suggesters: 0

Security: 0

Stars: 3

Watchers: 2

Forks: 0

Open Issues: 0

Type:project

v0.1.3 2018-10-25 13:44 UTC

This package is auto-updated.

Last update: 2022-07-29 02:33:35 UTC


README

部署

安装

git clone https://github.com/warnstar/tin.git
cd tin
composer install

启动

php public/index.php

路由配置

任意文件内配置路由对象,然后注入到application中启动

// 实例化路由处理器对象
$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');
});

请求处理

获取请求参数

在action控制器运行

获取请求头

$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();