我正在为 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',
));
我已经使用相同的方法为其他页面实现了分页,但在权限模块中它不起作用。它没有显示任何错误,但也没有显示分页链接/按钮。