查看页面:
<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>
主要.js
function LoginCtrl($scope, $http) {
$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";
});
}
登录 Controller :
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 Controller 。希望对您有所帮助。
关于php - 如何将数据从 angular js 发布到 zend Controller ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18307876/