sml / sml-frame
一个简单的框架,用于轻松处理API
v0.0.5
2017-05-13 21:59 UTC
Requires
- firebase/php-jwt: ^3.0
This package is not auto-updated.
Last update: 2024-09-29 02:34:09 UTC
README
入门指南
运行 composer install 修改 .htaccess 文件以匹配您的文件结构
基本设置
require_once 'vendor/autoload.php'; $app = new Sml\Sml(); # Run the application $app->run();
使用请求进行路由
require_once 'vendor/autoload.php'; $app = new Sml\Sml(); $app::get('/', function(){ echo 'test'; }); # If you want to pass arguments to the function you do this with regEx values # Supported values are for Strings and Ints # String and int value $app::get('/user/(\w+)/(\d+)', function( $string, $int ){ # You can then use the params here }); # POST $app::post('/user', function() use( $app ) { # To get the post request you can do: # This recives a json encoded body for you, and returns as obj. # If you want a array you can pass true into the json( true ) $app->request()->json(); # This recives the x-www-form-urlencoded body ( normal POST ) $app->request()->body(); }); # Run the application $app->run();
响应
要使用响应对象,您需要在函数中注入 $app
require_once 'vendor/autoload.php'; $app = new Sml\Sml(); $app::get('/', function() use( $app ){ $app->response( 200, "it Works" )->send(); }); # You can also send back json_response by chaining the sendJson method onto the response method. $app::get('/', function() use( $app ){ $app->response( 200, "it Works" )->sendJson(); }); $app->run();
更新日志
版本 0.0.2
- 添加了对 POST、GET、PUT、DELETE 路由的支持
- 添加了用于处理错误的异常类
- 添加了响应对象
- 添加了请求对象
- 添加了对环境文件的使用
版本 0.0.1
- 包含简单的 GET 路由支持。