【发布时间】:2016-09-26 16:26:31
【问题描述】:
我有一个离子应用程序,我想用我通过 php 脚本获得的数据填充其中一个页面。所以,我的 php:
<?php
$user = 'username';
$pass = 'mypass';
$client = new SoapClient('http://mywebsite.rs/api/soap/?wsdl', array('soap_version' => SOAP_1_2));
try {
$session = $client->login($user, $pass);
$result = $client->call($session, 'api_category.rootcategories');
print_r ( $result);
$client->endSession($session);
} catch (Exception $e) {
echo "Error: ".$e->getMessage();
}
?>
现在。我想在我的主页上打印结果。什么是输出它的简单方法?问题是我不知道如何从离子框架调用该文件。我确实有一些代码,我进行了实验,但它不起作用:
.controller('AppCtrl', function($scope, $http,$state ,$ionicModal,$ionicHistory,$ionicNavBarDelegate,SearchData,$window) {
$scope.categories = [];
var numberOfRow = 1;
var link = 'app/getAllCats.php';
$http.post(link).then(function (res){
$scope.categories = res.data;
for(var i = 0 ; i<res.data.length ; i++){
if(res.data[i].is_active === 1)
$scope.categories.push(res.data[i]);
}
arrayLength = $scope.categories.length;
numberOfRow = ~~(arrayLength / 3);
var div = arrayLength - numberOfRow;
if(div <=2 || div >=1 ){
numberOfRow = numberOfRow + 1;
}
});
$scope.range = function(){
return new Array(numberOfRow);
}
$scope.create = function(id){
$state.go('fooBar',{category_id: id});
}
console.log($scope.categories);
})
【问题讨论】:
-
以json的形式发送数据,然后在controller show in view中读取。
-
我该怎么做?代码示例将非常有帮助
标签: php angularjs ionic-framework