Dalam tampilan admin kita menjumpai button untuk view, update dan delete. Kita ingin menampilkan tombol-tombol tersebut sesuai dengan access control list (ACL) yang diberikan.  Dalam Yii kita bisa memodifikasi pada bagian template.
        array(
            ‘class’=>’CButtonColumn’,
             ‘template’=>$template,

Misalnya ada program Umum::Checkme($program) yang akan mengecek apakah kita mempunyai hak akses di program tersebut. Jika ada maka kita akan menambahkan code pada $template. Variabel $template ini kemudian dimasukkan ke widget CGridView pada bagian CButtonColumn.

Untuk code lengkapnya bisa dilihat seperti di bawah ini, silahkan dilihat mulai $template=”{view}”;

<?php if (Umum::chekMe(“mutationOrder/create”)) echo CHtml::Button(‘Add’,array(‘onClick’=>”location=’index.php?r=mutationOrder/create&branch_id=0′”)); ?>
<?php
$template=”{view}”;
$controller=”mutationOrder”;

$action=”update”;
if (Umum::chekMe(“$controller/$action”))
{
    $template .='{‘.”$action”.’}’;
}

$action=”send”;
if (Umum::chekMe(“$controller/$action”))
{
    $template .='{‘.”$action”.’}’;
}

$action=”correction”;
if (Umum::chekMe(“$controller/$action”))
{
    $template .='{‘.”$action”.’}’;
}

$action=”approve”;
if (Umum::chekMe(“$controller/$action”))
{
    $template .='{‘.”$action”.’}’;
}

$action=”print”;
if (Umum::chekMe(“$controller/$action”))
{
    $template .='{‘.”$action”.’}’;
}

$action=”delete”;
if (Umum::chekMe(“$controller/$action”))
{
    $template .='{‘.”$action”.’}’;
}

 $this->widget(‘zii.widgets.grid.CGridView’, array(
    ‘id’=>’mutation-order-grid’,
    ‘dataProvider’=>$model->search(),
    ‘filter’=>$model,
    ‘columns’=>array(
        ‘mutation_no’,
        ‘branch.branch_name’,
        ‘store.store_name’,
         array(     
            ‘name’=>’mutation_type’,
            ‘value’=>’$data->getMutTypeStr($data->mutation_type)’ ,
        ),        
        ‘date_mutation’,
        ‘store.store_name’,
         array(     
            ‘name’=>’cd_status’,
            ‘value’=>’$data->getStatusStr($data->cd_status)’ ,
        ),        
        array(
            ‘class’=>’CButtonColumn’,
             ‘template’=>$template,
            ‘deleteConfirmation’=>”js: ‘Are you want to delete ‘+$(this).parent().parent().children(‘:first-child’).text()+ ‘?'”,       
            ‘buttons’=>array
            (

                ‘update’ => array
                (
                    ‘visible’=>’$data->cd_status==0’,
                ),

                ‘delete’ => array
                (
                    ‘visible’=>’$data->cd_status==0’,
                ),
            
                ‘send’ => array
                (
                    ‘label’=>’S’,
                    ‘options’=>array(‘title’=>’Send for Approve’,’class’=>’pes_action’),
                    ‘url’=>’Yii::app()->createUrl(“receiveOrder/send”, array(“id” => $data->receive_order_id,”exe” => 0))’,
                    ‘visible’=>’$data->cd_status==0’,
                ),

                ‘correction’ => array
                (
                    ‘label’=>’C’,
                    ‘options’=>array(‘title’=>’Correction to Draft’,’class’=>’pes_action’),
                    ‘url’=>’Yii::app()->createUrl(“receiveOrder/correction”, array(“id” => $data->receive_order_id,”exe” => 0))’,
                    ‘visible’=>’$data->cd_status==1’,
                ),

                ‘approve’ => array
                (
                    ‘label’=>’A’,
                    ‘options’=>array(‘title’=>’Approve’,’class’=>’pes_action’),
                    ‘url’=>’Yii::app()->createUrl(“receiveOrder/approve”, array(“id” => $data->receive_order_id,”exe” => 0))’,
                    ‘visible’=>’$data->cd_status==1’,
                ),

                ‘void’ => array
                (
                    ‘label’=>’V’,
                    ‘options’=>array(‘title’=>’Void’,’class’=>’pes_action’),
                    ‘url’=>’Yii::app()->createUrl(“receiveOrder/void”, array(“id” => $data->receive_order_id,”exe” => 0))’,
                    ‘visible’=>’$data->cd_status==2’,
                ),

                ‘print’ => array
                (
                    ‘label’=>’P’,
                    ‘options’=>array(‘title’=>’Print’,’class’=>’pes_action’,’target’=>’cetak’),
                    ‘url’=>’Yii::app()->createUrl(“receiveOrder/print”, array(“id” => $data->receive_order_id))’,
                    ‘visible’=>’$data->cd_status==2’,
                ),
            )

        ),
           
    ),
)); ?>

Kemudian pada main.css tambahkan
.pes_action
{
    font-weight:bold;
    margin-left:2px;
    margin-right:2px;
    padding-left: 1px;
    padding-right: 1px;
    border: 1px solid #777;
    text-decoration: none;
}

Kunjungi www.proweb.co.id untuk menambah wawasan anda.

Customisasi CButtonColumn sesuai ACL di Yii