# 微擎模块脚手架 **Repository Path**: forapi/we7_test ## Basic Information - **Project Name**: 微擎模块脚手架 - **Description**: php > 5.4 1. 路由转发 中间件 psr7标准 2. 微擎模块种使用laravel 数据库 个人项目 非官方支持 - **Primary Language**: PHP - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 2 - **Created**: 2018-07-08 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 微擎模块脚手架 > 个人项目 非官方推荐 #### 个人项目 非官方推荐 > 小程序helloword php > 5.4 1. 路由转发 中间件 psr7标准 中间件未遵循psr15 标准 (大神仓库没更新) 2. 微擎模块种使用laravel 数据库 简单hack下 ### 资源 [composer 组合一个框架粗来](https://lvwenhan.com/php/405.html) [composer 微框架](https://laravel-china.org/articles/6271/build-a-micro-framework-for-your-project-using-composer) 推荐大神仓库 http://thephpleague.com/ [文件系统](http://flysystem.thephpleague.com/docs/) http://flysystem.thephpleague.com/docs/+ [视图模板](http://platesphp.com/) http://platesphp.com/ [事件](http://event.thephpleague.com/2.0/) http://event.thephpleague.com/2.0/ [支付](http://omnipay.thephpleague.com/) http://omnipay.thephpleague.com/ ~~~ /** * 因微擎屏蔽了 数据库的连接配置信息 需要hack 一下 */ $manager->getDatabaseManager()->extend('default', function(){ $connection = new \Illuminate\Database\MySqlConnection(pdo()->getPDO()); return $connection; }); ~~~ 个人项目 #### 测试访问地址 http://127.0.0.1:89/app/index.php?i=941&c=entry&a=wxapp&do=query&m=we7_test composer 组合起来的脚手架 [https://github.com/thephpleague/route](https://gitee.com/gitee-stars/) #### 路由定义 ~~~ $route = new \League\Route\RouteCollection($container); $route->get('/hello', function(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Message\ResponseInterface $response){ $body = $response->getBody(); $body->write('123456'); return $response; })->middleware(new \We7Test\Middleware\HelloMiddleware()); $route->get('/query', 'We7Test\Controller\IndexController::index'); return $route; ~~~ #### 数据库查询 ~~~ getQueryParams();//查询query $result = DB::table($user_table)->limit(19)->get();//原生查询 $users = User::query()->limit(10)->get(); // 对象方式 $response = $response->withHeader('content-type', 'application/json'); $response->getBody()->write(json_encode(['params'=>$params, 'db'=>$result, 'users'=>$users])); return $response; } } ~~~ #### composer.json ~~~ { "require": { "league/route": "^3.0", "zendframework/zend-diactoros": "^1.7", "illuminate/database": "5.4.*" }, "autoload": { "psr-4": { "We7Test\\": "./" } } } ~~~ #个人项目 非官方推荐