PHP code example of mongdch / fapi

1. Go to this page and download the library: Download mongdch/fapi 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/ */

    

mongdch / fapi example snippets



/**
 * 路由DEMO
 */
 = \FApi\App::instance()->init(true);

// 控制器调用演示
$app->route->group(['path' => '/class', 'namespace' => '\App\Controller\\'], function($r){
    $r->get('', 'Index@action');
});

// 匿名方法调用
$app->route->post(['path' => '/test', 'befor' => 'Middleware', 'after' => 'After'], function(){
    return 'This is Middleware and after demo!';
});

// 多种请求方式
$app->route->map(['GET', 'POST'], '/', function(){
	echo 'more query method';
})

// 默认路由, 没有对应路径的时候,调用 * 回调
$app->route->any('*', 'App\Controller\Index@index');


// 执行应用, 获取响应对象
$response = $app->run();

// 获取响应内容
$result = $app->getResult();

// 输出响应对象
$response->send();