Php 引导表数据url

Php 引导表数据url,php,json,twitter-bootstrap-3,Php,Json,Twitter Bootstrap 3,我正在使用Bootstrap Table(),我在使用数据url将数据“绑定”到表时遇到了问题 这是我的表格代码: <table data-toggle="table" data-side-pagination="server" data-url="<? echo $letServiceHandler->getEmployees($_SESSION['api_key'],2); ?>" data-cache="false" data-height="299"> &l

我正在使用Bootstrap Table(),我在使用数据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如下所示:

[
 {"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"}
]
// 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']);
}
请注意,我正在解码响应,然后再次编码,只选择employees嵌套数组


我尝试将json_encode($decoded['employees'])输出并创建一个数据文件,将其放入一个名为data.json的文件中,并将其插入我的数据url。这非常有效。

与表的开发人员联系后,我发现通过将数据url设置为php函数将数据插入表中的尝试不是使用此“属性”的正确方法

我需要将我的函数放入一个单独的php文件中,以使其工作,正如我在上面的评论中所提到的那样

因此,解决方案是:

<table data-toggle="table" data-side-pagination="server" data-url="getEmployees.php?id=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>

项目ID
项目名称
项目价格

getEmployee.php将向我的Web服务发出请求,并返回结果,然后将结果应用到表中。

到目前为止,我通过将getEmployee函数放入一个单独的文件(getEmployee.php)中解决了我的问题,该文件执行与以前的函数相同的操作,只是没有使用php函数。这最终奏效了,但我还是有点困惑,调用数据url内的函数和放置指向文件的链接两者之间有什么区别。。