【发布时间】:2014-03-31 11:24:20
【问题描述】:
我从框架 Yii 中的 CGridView 中使用,我希望当我单击视图按钮时,它会在新窗口中打开 如何添加目标的“_new”?
【问题讨论】:
-
你试过什么。请参阅此链接:yiiframework.com/wiki/48/by-example-chtml
标签: php yii target cgridview cbuttoncolumn
我从框架 Yii 中的 CGridView 中使用,我希望当我单击视图按钮时,它会在新窗口中打开 如何添加目标的“_new”?
【问题讨论】:
标签: php yii target cgridview cbuttoncolumn
在CGridView的CButtonColumn配置数组中添加'options' => array('target'=>'_new')
array(
'class'=>'zii.widgets.grid.CButtonColumn',
'template' => '{view}',
'buttons'=>array(
'view' => array(
'url' => '', // view url
'options' => array('target' => '_new'),
),
),
),
【讨论】:
您可以使用 'options' 属性来提供 html 属性。
<?php
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider' => $dataProvider,
'columns' => array(
'table_field_1',
'table_field_2',
'table_field_3',
array(
'class' => 'CButtonColumn',
/* ===== Template to set the buutons. Ex: If you dont want delete link, remove {delete} */
//'template' => '{view} {update} {delete}',
'buttons' => array(
'view' => array(
'options' => array('class' => 'newWindow'),
),
),
),
),
));
?>
但是,打开一个新窗口取决于浏览器。使用target="_blank" 和target="_new" 链接将在Mozilla 的新选项卡中打开,但在IE 中您将获得新窗口。所以用户 javascript 来生成新窗口。
<?php
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider' => $dataProvider,
'columns' => array(
'table_field_1',
'table_field_2',
'table_field_3',
array(
'class' => 'CButtonColumn',
/* ===== Template to set the buutons. Ex: If you dont want delete link, remove {delete} */
//'template' => '{view} {update} {delete}',
'buttons' => array(
'view' => array(
'options' => array('class' => 'newWindow'),
),
),
),
),
));
?>
将此 jQuery 保存在您的 .js 文件中
<script>
$(document).ready(function()
{
$(".newWindow").click(function(e)
{
e.preventDefault();
var url=$(this).attr('href');
window.open(url, "_blank", "toolbar=no, scrollbars=yes, resizable=yes, top=100, left=100, width=1020, height=500");
});
});
</script>
【讨论】:
你可以用这个
<?php
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider' => $dataProvider,
'columns' => array(
'table_field_1',
'table_field_2',
'table_field_3',
array(
'class' => 'CButtonColumn',
/* ===== Template to set the buutons. Ex: If you dont want delete link, remove {delete} */
//'template' => '{view} {update} {delete}',
'buttons' => array(
'view' => array(
'options' => array('target' => '_blank'),
),
),
),
),
));
?>
【讨论】: