3

我正在尝试在 yii1.1 中grideview使用它的 id 及其前后元素 id 创建一个链接。

array(
    'class' => 'bootstrap.widgets.TbButtonColumn',
    'template' => '{manage}',
    'buttons' => array(
        'manage' => array(
            'label' => 'Manage',
            'icon' => 'th',                            
            'url' => Yii::app()->createUrl(
                "/member/data/manage",
                array("id" => $data->id, "prev" => ???, "post" => ???)
            ),
        ),
    ),
),

这是我想要的输出。 在此处输入图像描述

4

1 回答 1

0

尝试下面的代码,不是很好的解决方案,但应该可以

array(
    'class' => 'bootstrap.widgets.TbButtonColumn',
    'template' => '{manage}',
    'buttons' => array(
        'manage' => array(
            'label' => 'Manage',
            'icon' => 'th',                            
            'url' => function ($data, $row, $widget) {
                    $pagination = $widget->grid->dataProvider->getPagination();
                    $widget->grid->dataProvider->setPagination(false);
                    $provider_data = $widget->grid->dataProvider->getData();
                    $widget->grid->dataProvider->setPagination($pagination);
                    return Yii::app()->createUrl(
                        "/member/data/manage",
                        array(
                            "id" => $data->id,
                            "prev" => isset($provider_data[$row - 1]) ? $provider_data[$row - 1]->id : '',
                            "post" => isset($provider_data[$row + 1]) ? $provider_data[$row + 1]->id : ''
                        )
                    );
                },
        ),
    ),
),
于 2017-02-23T11:59:42.803 回答