我正在开发此网站,希望在该网站上使用angularjs从我的php调用数组并在html上显示列表,但我似乎不知道问题是否出在我的php还是我的我没有得到任何东西。
我尝试过json_encode();但我仍然一无所有
这是我的
contalist.php
<?php
function connect_AD()
{
$adServer = "ldap://WEB-SERVER.dimersoft.com";
session_start();
$ldap = ldap_connect($adServer);
$ldap_id[] = $ldap;
$ldap_id[] = $ldap;
$username = 'ddavid';
$password = 'G0vbi@2018';
$ldaprdn = 'dimersoft' . "\\" . $username;
ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($ldap, LDAP_OPT_REFERRALS, 0);
$bind = @ldap_bind($ldap, $ldaprdn, $password);
if ($bind)
{
$filter="(objectCategory=person)";
$result = ldap_search($ldap_id,"dc=DIMERSOFT,dc=COM",$filter)
or exit ('unable to make a search');
foreach ($result as $value)
{
if (ldap_count_entries($ldap, $value) > 0)
{
$search = $value;
break;
}
}
if ($search)
{
$info = ldap_get_entries($ldap, $search);
for ($x = 0; $x < $info['count']; $x++) {
$contacts=[
'name'=>$info[$x]["name"][0],
'email'=>$info[$x]["mail"][0],
'phone'=>$info[$x]["telephonenumber"][0],
'username'=>$info[$x]["samaccountname"][0],
'officialmail'=>$info[$x]['userprincipalname'][0]];
$data=$contacts
echo json_encode($data,JSON_PRETTY_PRINT);
}
}
ldap_unbind($ldap);
}
}
connect_AD();
?>
这是我的有角度的脚本
<script>
var myApp = angular.module('myApp', ['ngRoute'])
.config(function ($routeProvider, $locationProvider){
$routeProvider
.when('/home', {
templateUrl: 'default.html',
})
.when('/contact-info/:contact_index', {
templateUrl: 'contact_info.html',
controller: 'contactInfoCtrl'
})
.controller('homeCtrl', function ($scope, ContactService){
$scope.contacts = ContactService.getContacts();
})
.factory('ContactService', [function () {
var factory = {};
factory.getContacts = function ($scope, $http) {
return contact;
}
// contact list, usually would be a separate database
return factory;
}]);
var contact = [];
contact.controller('ContactService', function($scope, $http) {
$http.get("js/contalist.php").then(function (response) {
$scope.contact = response.data.records;
});
});
</script>
这是我在html中的ng-repeate循环
<script type="text/ng-template" id="contact.html">
<a ng-href="#/contact-info/{{contacts.indexOf(contact)}}">
{{contact.name}}</a>
</script>
我希望看到名称列表,例如:
John doe
Peter Pan
Marry Jane
并使用以下脚本:
<script type="text/ng-template" id="contact_info.html">
<div class="list-group-item">
<h3 class="text-center">{{currentContact.name}}</h3>
<p>email: <a ng-href="{{currentContact.mail}}">{{currentContact.email}}</a></p>
<p>phone: {{currentContact.phone}}</p>
<p>username: <a ng-href="{{currentContact.username}}">{{currentContact.username}}</a></p>
<p>officialmail:</p><p class="well well-lg">{{currentContact.officialmail}}</p>
</div>
</script>
我应该看到所选名称的详细信息,例如:
John Doe
email:example@domain.com
phone:123456789
username:jdoe
officialmail:jdoe@domain.com
但是它是空的,我什么也没得到,但是当我运行php本身时仍然如此:
{ "name": "David Masanga", "email": null, "phone": null, "username": "dmasanga", "official-mail": "dmasanga@dimersoft.com" }
{ "name": "Blaise Atangana", "email": null, "phone": null, "username": "batangana", "official-mail": "batangana@dimersoft.com" }
{ "name": "Michelline Bwimba", "email": null, "phone": null, "username": "mbwimba", "official-mail": "mbwimba@dimersoft.com" }
{ "name": "dimers david", "email": "dimersdavid@gmail.com", "phone": "100101", "username": "ddavid", "official-mail": "ddavid@dimersoft.com" }
{ "name": "java Dimers", "email": null, "phone": null, "username": "jdimers", "official-mail": "jdimers@dimersoft.com" }
有人可以帮忙吗