如何在使用cakephp 1.3创建的web应用程序中实现jqgrid v3.7

时间:2010-07-01 07:26:49

标签: cakephp jqgrid cakephp-1.3 jqgrid-php

我正在尝试在使用cakephp v1.3创建的web应用程序中实现 jqgrid v3.7

我的控制器代码如下

function admin_index()
{
    // get how many rows we want to have into the grid - rowNum parameter in the grid
    $limit = $this->params['url']['rows'];

    // get index row - i.e. user click to sort. At first time sortname parameter -
    // after that the index from colModel
    $sidx = $this->params['url']['sidx'];

    // sorting order - at first time sortorder
    $sord = $this->params['url']['sord'];

    // if we not pass at first time index use the first column for the index or what you want
    if( !$sidx ) $sidx = 1;

    // calculate the number of rows for the query. We need this for paging the result
    $row = $this->Constituency->find('count');
    $count = $row;

    // calculate the total pages for the query
    if( $count > 0 )
    {
        $total_pages = ceil($count / $limit);
    }
    else
    {
        $total_pages = 0;
    }

    // if for some reasons the requested page is greater than the total
    // set the requested page to total page
    if( $page > $total_pages ) $page = $total_pages;

    // calculate the starting position of the rows
    $start = $limit * $page - $limit;

    // if for some reasons start position is negative set it to 0
    // typical case is that the user type 0 for the requested page
    if( $start < 0 ) $start = 0;

    // the actual query for the grid data
    $limit_range = $start . "," . $limit;
    $sort_range = $sidx . " " . $sord;
    //$result = $this->Constituency->findAll(null, "id,name", $sort_range, $limit_range, 1, null);
    $this->Constituency->recursive = -1;
    $result = $this->Constituency->find('all', array(
        'fields' => array('id', 'name'),
        'order' => $sidx,
        'limit' => $start .",". $limit_range
    ));

    $i=0;
    $response->page = $page;
    $response->total = $total_pages;
    $response->records = $count;

    foreach($result as $result)
    {
        $response->rows[$i]['id'] = $result['Constituency']['id'];
        $responce->rows[$i]['cell']=array($result['Constituency']['id'],$result['Constituency']['name']);
        $i++;
    }

    echo json_encode($response);
}

视图文件包含以下代码

$this->Html->css('ui.jqgrid');
$this->Html->script('jquery.jqGrid.min');

<script type="text/javascript">
    $(document).ready(function(){
        $("#list").jqGrid(
        {
            url:'<?php echo $this->Html->url(array("controller" => "constituencies", "action" => "index")); ?>',
            datatype: "json",
            colNames:['Id','Name'],
            colModel:[
                {name:'id',index:'id', width:55},
                {name:'name',index:'name', width:90},
            ],
            rowNum:10,
            rowList:[10,20,30],
            pager: jQuery('#pager'),
            sortname: 'id',
            viewrecords: true,
            sortorder: "desc",
            caption:"Constituencies"
        });
        $("#list").navGrid("#pager",{edit:false,add:false,del:false});
    })
</script>

<div class="constituencies index">
    <h2><?php __('Constituencies'); ?></h2>
    <table id="list"  class="scroll"></table>
    <div id="pager"  class="scroll" ></div>
</div>

现在,当我加载索引操作时,我会遇到很多错误

  

未定义的索引:行   未定义的索引:sidx   未定义的索引:sord   等等。

有没有人在基于cakephp的应用程序中包含jqgrid?

如何在我的应用程序中包含jqgrid? 请帮我这样做。

由于

3 个答案:

答案 0 :(得分:1)

答案 1 :(得分:1)

您获得的错误看起来像PHP错误。尝试在视图文件的顶部放置debug($this->params);语句,以查看控制器正在吐出的内容。

答案 2 :(得分:1)