Php 如何将数据从angular js发布到zend controller?

Php 如何将数据从angular js发布到zend controller?,php,angularjs,zend-framework2,Php,Angularjs,Zend Framework2,查看页面: <div ng-controller="LoginCtrl"> <form name="login_form" ng-submit="submit()" > Email: <input type="email" ng-model="login.email" required/><br /> Password: <input type="password" ng-model="login.pass" required

查看页面:

<div ng-controller="LoginCtrl">
<form name="login_form" ng-submit="submit()" >
    Email: <input type="email" ng-model="login.email" required/><br />
    Password: <input type="password" ng-model="login.pass" required/><br />

    <input type="submit" />
</form>
登录控制器:

if ($request->isPost()) {
            $data = json_decode(file_get_contents("php://input"));}

我需要从angular表单中获取数据并将其传递给zend controller,然后执行登录检查和提交表单。有人可以帮助我逐步解释吗?

像这样更改main.js

function LoginCtrl($scope, $http) {
$scope.login = {email: "", password: ""};
$scope.login = $.param($scope.login);
$scope.submit = function(){

    $http({
        method: 'POST',
        url: '/login',
        data: $scope.login,
        headers: {'Content-Type': 'application/x-www-form-urlencoded'}

    }).
        success(function(response) {
            window.location.href = "/login";
        }).
        error(function(response) {
            $scope.codeStatus = response || "Request failed";
        });
}
在你的php文件中访问你的电子邮件和密码

$email = $_REQUEST['email'];
$password = $_REQUEST['password'];

并将这些凭据发送到您的zend控制器。希望能有所帮助。

我发现了另一篇关于angular不以php期望的方式发送数据的帖子。也就是说,它正在进行json编码。当我遇到这个问题时,请求是空的。查看以下帖子:


要成为有效的HTTP帖子,您不需要将HTML名称附加到JSON提交中吗?在登录控制器中,添加
错误日志(文件获取内容(“php://input") );此问题似乎与主题无关,因为它与教程有关
$email = $_REQUEST['email'];
$password = $_REQUEST['password'];