dongzhang4301 2013-11-18 18:07
浏览 35
已采纳

Yii:如果变量等于0图标作为链接,否则图标打开警报

I have CButtonColumn in CGridView:

array(
            'class' => 'CButtonColumn',
                        'template'=>'{document}',
                        'buttons'=>array(
                            'document'=>array(
                                'imageUrl'=>'icon.gif',
                                'url' => '($data->status=="1") ? Yii::app()->createUrl("site/getDocument") : "" ',
                                'click' => 'js:function() { alert("There isn't file");}'
                            ),
                        ),
        ),

But I want open will be opening alert only when $data->status=="1", but I can't insert php code in 'click'. So There is any possibility to do this?

  • 写回答

1条回答 默认 最新

  • dongyin8991 2013-11-19 03:48
    关注

    From http://www.yiiframework.com/doc/api/1.1/CButtonColumn:

    'buttonID' => array(
        'label'=>'...',     // text label of the button
        'url'=>'...',       // a PHP expression for generating the URL of the button
        'imageUrl'=>'...',  // image URL of the button. If not set or false, a text link is used
        'options'=>array(...), // HTML options for the button tag
        'click'=>'...',     // a JS function to be invoked when the button is clicked
        'visible'=>'...',   // a PHP expression for determining whether the button is visible
    )
    

    "In the PHP expression for the 'url' option and/or 'visible' option, the variable $row refers to the current row number (zero-based), and $data refers to the data model for the row. A PHP expression can be any PHP code that has a value." You can access elements on DOM to get the values you want.

    You can try this:

    array(
          'class' => 'CButtonColumn',
                'template'=>'{document}',
                'buttons'=>array(
                            'document'=>array(
                            'imageUrl'=>'icon.gif',
                            'url' => '($data->status=="1") ? Yii::app()->createUrl("site/getDocument") : "" ',
    
                    'click' => 'function() { if($(this).attr("href") !== "") alert("There isn't file");}',
                                ),
                            ),
            ),
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么