sasori
sasori

Reputation: 5445

How to put two imagelink in one column of yii framework grid?

Here is what I currently have:

$columns[] = array(
  'header' => 'Share',
  'type'   => 'html',
  'value'  => "CHtml::link(CHtml::image('http://www.mysite.com/images/icons/fb.jpg'),'#',array())",
);

what I want to happen is, add the twitter share button as well, just beside that fb button. How to do that?

Upvotes: 2

Views: 551

Answers (1)

bool.dev
bool.dev

Reputation: 17478

You can use a CButtonColumn instead:

array(
    'class'=>'CButtonColumn',
    'header'=>'Share',
    'template'=>'{fbButton}{twButton}',
    'buttons'=>array(
        'fbButton'=>array(
            'imageUrl'=>Yii::app()->baseUrl.'/images/icons/facebook-circle.png',
            'url'=>'"http://www.facebook.com"'
        ),
        'twButton'=>array(
            'imageUrl'=>Yii::app()->baseUrl.'/images/icons/twitter-circle.png',
            'url'=>'"http://www.twitter.com"'
        )
    )
),

The template decides of course the buttons to be displayed in the column, and buttons describes the configuration for each button. So in general we specify:

'template'=>'{buttonId1}{buttonId2}',
'buttons'=>array(
    'buttonsId1'=>array(/*buttonid1 configuration*/),
    'buttonsId2'=>array(/*buttonid2 configuration*/),
)

For each button's configuration we can specify the label, url, imageUrl, options, click, visible, this is already given in the documentation link for buttons. Using click we can specify a js function to be invoked when the button is clicked.

Upvotes: 3

Related Questions