【问题标题】:when I click view button in CGridView, it is opened in a new window当我单击 CGridView 中的查看按钮时,它会在新窗口中打开
【发布时间】:2014-03-31 11:24:20
【问题描述】:

我从框架 Yii 中的 CGridView 中使用,我希望当我单击视图按钮时,它会在新窗口中打开 如何添加目标的“_new”?

【问题讨论】:

标签: php yii target cgridview cbuttoncolumn


【解决方案1】:

在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'),
        ),
    ),
),

【讨论】:

    【解决方案2】:

    您可以使用 '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>
    

    【讨论】:

      【解决方案3】:

      你可以用这个

      <?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'),
                      ),
                  ),
              ),
          ),
      ));
      ?>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2015-09-09
        • 1970-01-01
        • 2021-03-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多