Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Yii CGridView hyperlink open in new tab

Tags:

php

yii

cgridview

I have made one column of my yii CGridview as a hyperlink. But on clicking it, it opens link address within the same tab. How can I open the link address in a new tab ?

array(
    'header'=>'Name',
    'name'  => 'name',
    'value' => 'CHtml::link($data->name, $data->site_url)',
    'type'  => 'raw',
),
like image 460
Soojoo Avatar asked Sep 16 '25 23:09

Soojoo


2 Answers

Set the target attribute as _blank for the link (<a>) that will be generated:

<a href="some_url" target="_blank">Foo</a>

With CHtml::link :

'value' => 'CHtml::link($data->name, $data->site_url, array("target"=>"_blank"))',

The last parameter to CHtml::link() (and most other html helpers in CHtml class), is htmlOptions, which is supposed to be an associative array with html attributes as keys and their values as values:

array(
    "target"=>"_blank",
    "class"=>"my-css-class",
    // ... any other html attribute ..
)
like image 118
bool.dev Avatar answered Sep 18 '25 16:09

bool.dev


You cannot create a new-tab-link in value field,I create the link by hand:

here's the code:

'value'=>'<a target=_blank href='.Yii::app()->createUrl('/user/index', array('id'=>$model->id)).'>Link</a>'
like image 36
aiddroid Avatar answered Sep 18 '25 16:09

aiddroid