1

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

4

1 回答 1

0

首先,queryAll返回一个数组。文档。因此,您可能应该使用queryScalar,并且应该从函数返回结果,而不是命令对象。

 return $max->queryScalar();

你也可以在 Yii 中使用统计查询。

其次,你想在按钮分别不在顶部或底部时显示按钮,所以你应该否定=

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

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

于 2012-12-11T10:31:06.387 回答