如何在yii grideview中传递前一个和后一个元素的id?

时间:2015-12-30 04:57:09

标签: gridview yii yii-booster

我正在尝试在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" => ???)
            ),
        ),
    ),
),

这是我想要的输出。 enter image description here

1 个答案:

答案 0 :(得分: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 : ''
                        )
                    );
                },
        ),
    ),
),