PHPmvc1(zend框架)中如何使用jtable?
How use jtable in PHP mvc1 (zend framework)?
我从 jtable.org 得到了 jtable。
当我在简单的 PHP 项目中使用 jtable 时,它工作正常,但是当我将它更改为 PHP mvc 时,它返回了以下错误并且没有显示任何jtable.
中的数据
An error occured while communicating to the server.
but in the chrom console it print 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>
显示 table 没有任何数据
我找到了答案
我在控制器中禁用了我的操作布局,并且一切正常,因为当 json returns 它与主布局 returns 并且当我通过添加新布局禁用布局时响应不正确没有任何 html 标签的布局它可以工作。
我从 jtable.org 得到了 jtable。
当我在简单的 PHP 项目中使用 jtable 时,它工作正常,但是当我将它更改为 PHP mvc 时,它返回了以下错误并且没有显示任何jtable.
中的数据An error occured while communicating to the server. but in the chrom console it print 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>
显示 table 没有任何数据
我找到了答案 我在控制器中禁用了我的操作布局,并且一切正常,因为当 json returns 它与主布局 returns 并且当我通过添加新布局禁用布局时响应不正确没有任何 html 标签的布局它可以工作。