4

我正在为 ACL 使用 Yii 权限模块,我希望对权限页面进行分页。

以下是我的代码:

AuthItemController.php

public function actionPermissions() {
        $dataProvider = new RPermissionDataProvider('permissions', array(
                    'pagination' => array(
                        'pageSize' => 10,
                        //'class' => 'CPagination', //showing an error
                        'itemCount' => 32
                        )));

        // Get the roles from the data provider
        $roles = $dataProvider->getRoles();
        $roleColumnWidth = $roles !== array() ? 75 / count($roles) : 0;

        // Initialize the columns
        $columns = array(
            array(
                'name' => 'description',
                'header' => Rights::t('core', 'Item'),
                'type' => 'raw',
                'htmlOptions' => array(
                    'class' => 'permission-column',
                    'style' => 'width:25%',
                ),
            ),
        );

        // Add a column for each role
        foreach ($roles as $roleName => $role) {
            $columns[] = array(
                'name' => strtolower($roleName),
                'header' => $role->getNameText(),
                'type' => 'raw',
                'htmlOptions' => array(
                    'class' => 'role-column',
                    'style' => 'width:' . $roleColumnWidth . '%',
                ),
            );
        }

        $view = 'permissions';
        $params = array(
            'dataProvider' => $dataProvider,
            'columns' => $columns,
        );

        // Render the view
        isset($_POST['ajax']) === true ? $this->renderPartial($view, $params) : $this->render($view, $params);
    }

而在View

$this->widget('bootstrap.widgets.TbGridView', array(
        'type' => 'bordered',
        'dataProvider' => $dataProvider,
        'template' => '{pager}{items}',
        'emptyText' => Rights::t('core', 'No authorization items found.'),
        'htmlOptions' => array('class' => 'grid-view permission-table'),
        'columns' => $columns,
        'pager' => array(
            'header' => '',
            'hiddenPageCssClass' => 'disabled',
            'maxButtonCount' => 3,
            'cssFile' => false,
            'class' => 'CLinkPager',
            'prevPageLabel' => '<i class="icon-chevron-left"></i>',
            'nextPageLabel' => '<i class="icon-chevron-right"></i>',
            'firstPageLabel' => 'First',
            'lastPageLabel' => 'Last',
        ),
        'pagerCssClass' => 'pagination',
    ));

我已经使用相同的方法为其他页面实现了分页,但在权限模块中它不起作用。它没有显示任何错误,但也没有显示分页链接/按钮。

4

1 回答 1

2

在一个页面中实现多个网格时我遇到了同样的问题,对我有用的解决方案是,我检查了网格 ajax 调用的 url,在更新之前我操纵了 url,并在 ajax 请求之前设置了正确的 url 和参数!

喜欢:

$this->widget('zii.grid.GridView', array(
  'id' => 'group-grid-customers-list-not-scheduled',
  'dataProvider' => $notScheduledVisitedDataProvider ,
  'beforeAjaxUpdate' => '
        function(id , options)
        { 
            options.url = options.url.split("&test=test&");
            options.url = options.url[0] + "&test=test&" + $(".search-form form").serialize(); 
        }',
  'columns' => array(
      'col1',
      'col2',
      'col3',
  ),
));
于 2013-09-23T08:58:03.593 回答