CakePHP + jqGrid整合的例子

html:
<table id="list47"></table>
<div id="plist47"></div>


js:
$(document).ready(function(){
jQuery("#list47").jqGrid({
//data: mydata,
url:"/sites/ajaxListAll?XDEBUG_SESSION_START=php_debug",
datatype: "json",
height: 150,
rowNum: 10,
rowList: [10,20,30],
colNames:['ID', '欢迎语句','显示订阅','显示联系方式','网站名称','网站邮箱','联系邮箱','电话','描述'],
colModel:[
{name:'site_id',index:'site_id', width:100},
{name:'wellcome_title',index:'wellcome_title', width:80},
{name:'is_subscription',index:'is_subscription', width:80},
{name:'is_contact',index:'is_contact', width:80},
{name:'name',index:'name', width:80},
{name:'site_email',index:'site_email', width:80},
{name:'site_contact_email',index:'site_contact_email', width:80},
{name:'tel',index:'tel', width:80},
{name:'descript',index:'descript', width:150}
],
pager: "#plist47",
viewrecords: true,
jsonReader: {
repeatitems: false
},
loadComplete:function(){
},
caption: "Manipulating Array Data"
});
});



Controller:
<?php
class SitesController extends AppController
{
public $name = "Site";
public function ajaxListAll()
{
$list=$this->Site->find("all");
$data=array();
for($i=0; $i<count($list); $i++){
$data[$i]['site_id'] = $list[$i]['Site']['site_id'];
$data[$i]['wellcome_title'] = $list[$i]['Site']['wellcome_title'];
$data[$i]['is_subscription'] = $list[$i]['Site']['is_subscription'];
$data[$i]['is_contact'] = $list[$i]['Site']['is_contact'];
$data[$i]['name'] = $list[$i]['Site']['name'];
$data[$i]['site_email'] = $list[$i]['Site']['site_email'];
$data[$i]['site_contact_email'] = $list[$i]['Site']['site_contact_email'];
$data[$i]['tel'] = $list[$i]['Site']['tel'];
$data[$i]['descript'] = $list[$i]['Site']['descript'];
}
if ($this->request->is('get')) { //这里怎么判断。可能根据情况,但是我使用这样判断是没问题的。
$result = array(
'rows' => $data,
'page' => 1,
'total' => 2,
'records' =>1
);
return new CakeResponse(array('body' => json_encode($result), 'status' => 200));
}
}

}
?>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值