Yii CGridView hyperlink open in new tab

假如想象 提交于 2020-01-24 17:07:05

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!