【发布时间】:2015-09-19 04:41:44
【问题描述】:
我从 jtable.org 获得了 jtable。
当我在简单的 PHP 项目中使用 jtable 时,它可以正常工作,但是当我将其更改为 PHP mvc 时,它返回以下错误并且它没有在 jtable 中显示任何数据。
与服务器通信时发生错误。 但在 chrom 控制台中,它会打印 JSON:
{
"Result":"OK",
"TotalRecordCount":"20",
"Records":[
{"PersonId":"1","0":"1","Name":"Benjamin Button","1":"Benjamin Button","Age":"17","2":"17","RecordDate":"2011-12-27 00:00:00","3":"2011-12-27 00:00:00"},
{"PersonId":"12","0":"12","Name":"damir","1":"damir","Age":"27","2":"27","RecordDate":"2015-09-17 12:17:53","3":"2015-09-17 12:17:53"}
]
}
这表明一切都是正确的,但 jtable 没有显示任何内容。
我做错了什么?
在adminlayout.phtml 中,我在$(document).ready 中使用了其他jQuery 函数,但是当我删除它们时它也不起作用。
$(document).ready(function () {
//Prepare jTable
$('#PeopleTableContainer').jtable({
title: 'Table of people',
paging: true,
pageSize: 2,
sorting: true,
defaultSorting: 'Name',
actions: {
listAction: root_url+'admin/index/personpagedsorted?action=list',
},
fields: {
PersonId: {
key: true,
create: false,
edit: false,
list: false
},
Name: {
title: 'Author Name',
width: '40%'
},
Age: {
title: 'Age',
width: '20%'
},
RecordDate: {
title: 'Record date',
width: '30%',
type: 'date',
create: false,
edit: false
}
}
});
//Load person list from server
$('#PeopleTableContainer').jtable('load');
在控制器中:我只使用列表动作。
public function personpagedsortedAction()
{
if ($_GET["action"]=="list")
{
$dbh=Zend_Registry::get('db');
$sth = $dbh->prepare("SELECT COUNT(*) AS RecordCount FROM people;");
$sth->execute();
$row = $sth->fetch(PDO::FETCH_BOTH);
$recordCount = $row['RecordCount'];
$jtSorting=$_GET["jtSorting"];
$jtStartIndex= $_GET["jtStartIndex"];
$jtPageSize= $_GET["jtPageSize"];
//Get records from database
// $result =$db->personselectinput($jtSorting, $jtStartIndex, $jtPageSize);
$str_sql="SELECT * FROM people ORDER BY " . $jtSorting . " LIMIT " . $jtStartIndex . "," . $jtPageSize . ";";
// $res=$db->query($str_sql);
// $res=$db->fetchAll($str_sql);
$sth = $dbh->prepare($str_sql);
$sth->execute();
//Add all records to an array
$rows = array();
while ( $result = $sth->fetch(PDO::FETCH_BOTH))
{
$rows[]=$result;
}
//Return result to jTable
$jTableResult = array();
$jTableResult['Result'] = "OK";
$jTableResult['TotalRecordCount'] = $recordCount;
$jTableResult['Records'] = $rows;
// i change print to echo and return but it didnt work too
print json_encode($jTableResult);
}
}
在edittest.phtml中: 我写了
<div id="PeopleTableContainer"></div>
显示没有任何数据的表格
【问题讨论】:
标签: php jquery zend-framework model-view-controller jquery-jtable