gonzalo123/angularpostrequestserviceprovider

Angular POST 请求服务提供商

dev-master / 1.0.x-dev 2015-03-04 19:32 UTC

This package is not auto-updated.

Last update: 2024-09-24 03:45:13 UTC


README

Build Status

当我们在 AngularJs 应用程序中工作时,POST 请求使用 Content-Type: application/json,Silex(以及 Symfony)假定使用 application/x-www-form-urlencoded。在这里,我们可以看到如何使用 Silex 处理这些请求:https://github.com/qandidate-labs/symfony-json-request-transformer

在这个小型项目中,我们将这个功能封装在一个 ServiceProvider 中。

通过 Composer 安装

{
    "require": {
        "gonzalo123/angularpostrequestserviceprovider": "~1.0"
    }
}

使用方法

use Silex\Application;
use G\AngularPostRequestServiceProvider;
use Symfony\Component\HttpFoundation\Request;

$app = new Application();
$app->register(new AngularPostRequestServiceProvider());

$app->post("/post", function (Application $app, Request $request) {
    return $app->json([
        'status' => true,
        'name'   => $request->get('name')
    ]);
});

$app->run();