简体   繁体   English

如何在PHP mvc1(zend框架)中使用jtable?

[英]How use jtable in PHP mvc1 (zend framework)?

I got jtable from jtable.org. 我从jtable.org获得了jtable。

When I use jtable in simple PHP projects it works fine, but when I change it to PHP mvc it returned the following error and it didn't show any data in jtable. 当我在简单的PHP项目中使用jtable时,它可以正常工作,但是当我将其更改为PHP mvc时,它返回以下错误,并且在jtable中未显示任何数据。

An error occured while communicating to the server. 与服务器通信时发生错误。 but in the chrom console it print JSON: 但在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"}
           ]
}

That shows every thing is correct, but jtable didn't show anything. 这表明每件事都是正确的,但是jtable没有显示任何东西。

What am I doing wrong? 我究竟做错了什么?

In adminlayout.phtml I use other jQuery functions in $(document).ready but when I deleted them it didn't work either. 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'); 

in controller: I only use list action. 在控制器中:我仅使用列表操作。

 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); } } 

in edittest.phtml: I wrote 在edittest.phtml中:我写道

 <div id="PeopleTableContainer"></div> 

that show the table without any data 显示表没有任何数据

我找到了在控制器中禁用动作布局的答案,并且一切正常,因为当json返回时,它以主布局返回,而当我通过添加没有任何html标签的新布局禁用布局时,响应不正确。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM