0

CGridViewWii フレームワークのウィジェットで特定の列データを表示/非表示にすることを検討しています。

CButtonColumnは3つのボタンを含むを持っています。ただし、特定の条件で、特定の行に別のものを表示したい。特定の行に表示されるものを決定する3つの異なる条件があります。

以下は、私がやりたいことを示しています。

| 1 | Title A | [hide][view][update]            <-- if (condition == 'a')
| 2 | Title B | [hide][view][update]            <-- if (condition == 'a')
| 3 | Title C | display text or link or button  <-- if (condition == 'b')
| 4 | Title D | display alternative buttons     <-- if (condition == 'c')

ここで取るべき最善のアプローチは何ですか?

'visible'=> $model->processingStatus != "processed"列全体が削除されるため、列には使用できません。代わりに各行をターゲットにする必要があります。

'visible'個々のボタンごとにパラメーターを使用する必要がありますか? 以下のコメントアウトされたコードを使用してこれを試しましたが、ページが壊れます。参考までに: CButtonColumn 自体で「visible」パラメーターを試してみましたが、必要なものではありません。さらに、どの行のステータスが読み取られているのかわからない。

または、コントローラーに関数を追加する必要がありますか? if/else ステートメントを実行して、表示される内容を返します。これはどのように機能しますか?

これが私のコードです:

<?php $this->widget('zii.widgets.grid.CGridView', array(
    'id'=>'my-grid',
    'dataProvider'=>$model->search(),
    'filter'=>$model,
    'columns'=>array(

        array(
            'name'=>'myid',
            'header'=>'ID',
            ),

        'Title',

        array(
            'class'=>'CButtonColumn',
            'visible'=> $model->status != "done",
            'template'=>'{hide}{view}{update}',
            'buttons'=>array(
                'hide'=>array(
                    'label'=>'Hide',                                                    //Text label of the button.
                    'imageUrl'=>Yii::app()->request->baseUrl . '/img/icons/bulb-off.png'    //Image URL of the button.
                    //'click'=>'function(){alert("Toggle Hide!");}',                    //A JS function to be invoked when the button is clicked.
                    //'options'=>array(),               //HTML options for the button tag.
                    //'url'=>'javascript:void(0)',              //A PHP expression for generating the URL of the button.
                    //'visible'=> $model->status == "done",     //A PHP expression for determining whether the button is visible.
                ),
                'view'=>array(
                    //Text label of the button.
                    'label'=>'View',
                    //Image URL of the button.
                    'imageUrl'=>Yii::app()->request->baseUrl . '/img/icons/view-record.png'
                ),
                'update'=>array(
                    'label'=>'Update/Edit',
                    'imageUrl'=>Yii::app()->request->baseUrl . '/img/icons/edit-pencil.png',
                    'url'=>'Yii::app()->createUrl("metadataandchapters/create?bookid=" . $data->bookid)',
                )
            )
        )
    )
)); ?>

私がここで十分な意味を持っていることを願っています!

4

2 に答える 2

1

visibleボタン オプションを使用する必要がありますが、PHP 式の文字列にする必要があります。

'visible'=> '$data->status == "done"',

http://www.yiiframework.com/doc/api/1.1/CButtonColumn#buttons-detail

于 2014-03-11T17:53:30.273 に答える
0

独自のクラスで CButtonColumn を拡張すると、この関数を、ボタンをレンダリングまたは非表示にする、または必要な変更を行うために必要なものに変更できるはずです。

/**
 * Renders a link button.
 * @param string $id the ID of the button
 * @param array $button the button configuration which may contain 'label', 'url', 'data-icon', 'imageUrl' and 'options' elements.
 * @param integer $row the row number (zero-based)
 * @param mixed $data the data object associated with the row
 */
protected function renderButton($id, $button, $row, $data)

関数の詳細http://www.yiiframework.com/doc/api/1.1/CButtonColumn#renderButton-detail

于 2014-03-11T21:56:18.557 に答える