0
即時通訊使用引導表(http://wenzhixin.net.cn/p/bootstrap-table/docs/examples.html)和我無法「綁定」我的數據使用data-url的表。引導表數據url
我的繼承人表的代碼:
<table data-toggle="table" data-side-pagination="server" data-url="<? echo $letServiceHandler->getEmployees($_SESSION['api_key'],2); ?>" data-cache="false" data-height="299">
<thead>
<tr>
<th data-field="id">Item ID</th>
<th data-field="name">Item Name</th>
<th data-field="price">Item Price</th>
</tr>
</thead>
</table>
getEmployee的叫我休息web服務將返回一個JSON數組,看起來像這樣:
[
{"id":"33","name":"5yhjtyjyas 444","active":"0","user_id":"1","no_of_reports":"0"},
{"id":"29","name":"AAA","active":"1","user_id":"1","no_of_reports":"0"},
{"id":"20","name":"aasdasd","active":"1","user_id":"1","no_of_reports":"0"}
]
getEmployee的是這樣的:
// Gets employees
public function getEmployees($api_key,$active)
{
$headers = array('Content-type: application/json','Authorization: '.$api_key,);
if($active==0)
{
$curl = curl_init(GET_ALL_INACTIVE_EMPLOYEES);
}
else if($active==1)
{
$curl = curl_init(GET_ALL_ACTIVE_EMPLOYEES);
}
else
{
$curl = curl_init(GET_ALL_EMPLOYEES);
}
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPGET, true);
curl_setopt($curl, CURLOPT_USERPWD, $api_key);
$curl_response = curl_exec($curl);
if ($curl_response === false)
{
$info = curl_getinfo($curl);
curl_close($curl);
die('error occured during curl exec. Additioanl info: ' . var_export($info));
}
curl_close($curl);
$decoded = json_decode($curl_response,true);
return json_encode($decoded['employees']);
}
請注意Im解碼響應,然後再次編碼,只選擇員工嵌套數組。
我試着「回顯」json_encode($ decode ['employees'])並創建一個數據文件並將其放入一個名爲data.json的文件中,並將其插入到我的數據網址中。這工作完美..
到目前爲止,我通過將我的getEmplooyees函數放入一個單獨的文件(getEmployee.php)來解決我的問題,該文件執行與我之前的函數相同的事情,除了沒有執行PHP函數。這結束了工作,但我仍然有點困惑之間的區別是什麼,調用一個函數內的數據網址,並把一個鏈接到一個文件,這樣做? .. – DTH