问题
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',
),
回答1:
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 ..
)
回答2:
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>'
来源:https://stackoverflow.com/questions/15737536/yii-cgridview-hyperlink-open-in-new-tab