无法访问苗条php中从角度4发送的POST变量

时间:2018-01-11 13:34:20

标签: json angular slim

我正在尝试使用slim php构建一个带有rest api构建的小角度4应用程序。我很难在特定路线上访问POST变量,而它在至少一条路线上完美运行。这是我的代码:

// Log In A League { "email": $email, "pass": $pass }
$app->post('/api/users/league-login', function(Request $request, Response $response){
  require "user_management/league_login.php";
  $logIn = new LeagueLogIn();
  $logIn->logIn($request->getParam("email"), $request->getParam("pass"));
});

Angular发送此JSON:

Object { email: “test@test.com", pass: "000" } 

这完美无缺。但是在这次溃败中,我无法使用$ request-> getParam()

访问POST变量
// Add Team To A League { "name": $name, "email": $email }
$app->post('/api/league/team', function(Request $request, Response $response){
  require "user_management/team_create.php";
  $user = authorizeToken($request->getHeader('Authorization'));
  $teamCreate = new TeamCreate();
  $teamCreate->create($request->getParam("name"), $request->getParam("email"), $user);
});

Angular发送此JSON

Object { name: "name", email: "test2@test.com" }

只要我在键上为请求手动添加双引号:

Object { "name": "name", "email": "test2@test.com" }

效果很好。

有人知道这是什么问题,或者我忽略了什么?

0 个答案:

没有答案