douyunjiaok300404 2012-12-11 04:10
浏览 66

自定义排序/向下Yii CGridView按钮

so, I want to make a new button in my CGridView. This is up & down arrow buttons which is will be used for sorting my articles. I've read a lot of how to make this kind of buttons. I already read the wiki of how to use this CGridView button also in this link.

And now I have this in my view :

array(
                'header' => 'Action',
                'class' => 'CButtonColumn',
                'template' => '{moveup}{movedown}{view}{delete}',
                'htmlOptions' => array('style' => 'width: 68px'),
                'buttons' => array
                    (
                    'moveup' => array
                        (
                        'label' => 'Move Up',
                        'imageUrl' => Yii::app()->request->baseUrl . '/images/move_up.png',
                        'url' => 'Yii::app()->createUrl("KB/moveup", array("id"=>$data->KBID))',
                        'visible' => '$data->KBORDER == KB::model()->getMax()',
                    ),
                    'movedown' => array
                        (
                        'label' => 'Move Down',
                        'imageUrl' => Yii::app()->request->baseUrl . '/images/move_down.png',
                        'url' => 'Yii::app()->createUrl("KB/movedown", array("id"=>$data->KBID))',
                        'visible' => '$data->KBORDER == KB::model()->getMin()',
                    ),
                ),
            ),

and this one in my model :

    public function getMax(){
            $sql = 'SELECT MAX(KBORDER) FROM KB';
            $max = Yii::app()->db->createCommand($sql);
            $max->queryAll();
            return $max;
        }

        public function getMin(){
            $sql = 'SELECT MIN(KBORDER) FROM KB';
            $min = Yii::app()->db->createCommand($sql);
            $min->queryAll();
            return $min;

}

All that codes running just fine. except for the visibility. I want to make the up button become invisible when it has the highest value of KBORDER or when it position is in the 1st place. And for the down button, it supposed to be invisible too when it has the lowest value of KBORDER or when it position is in the last place. but, when I put that code in my 'visible', all the buttons are invicible. so my question is, how to make my request happen?

thanks in advance

  • 写回答

1条回答 默认 最新

  • dtueufe82643 2012-12-11 10:31
    关注

    First off, queryAll returns an array. Documentation. So you should probably use queryScalar, and you should return the result from the function, not the command object.

     return $max->queryScalar();
    

    You could also use a statistical query in Yii.

    Secondly, you want to SHOW the button when it is not in the top or bottom respectivily, so you should negate the =

    'visible' => '$data->KBORDER != KB::model()->getMax()',

    and

    'visible' => '$data->KBORDER != KB::model()->getMin()',

    评论

报告相同问题?

悬赏问题

  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法