如何使用CGridView添加自定义button

看了API手册的代码实例,感觉应该这样写:




<?php $this->widget('zii.widgets.grid.CGridView', array(

	'id'=>'category-grid',

	'dataProvider'=>$model->search(),

	'filter'=>$model,

	'columns'=>array(

		'id',//其中的一个字段

		'level',//其中的一个字段

		'name',//其中的一个字段

		array(//这个数组尝试添加自定义的按钮

			'class'=>'CButtonColumn',

			'buttons'=>array(

					 'upbutton' => array(

			    'label'=>'up',     // text label of the button

			    'url'=>array("category/index"),       // a PHP expression for generating the URL of the button

			    'imageUrl'=>false,  // 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

			)

		

		),

			'template'=>'{view}{update}{delete}{upbutton}',

		)

)));



尝试很多次,都不成功。有做过这个功能的吗,请提供一个具体的例子。谢谢。

visible这个属性 该怎么写PHP条件表达式呢·····

:rolleyes:

下面有一段例子~~ 注意,visible后面跟的php表达式需要加引号




array

(

    'class'=>'CButtonColumn',

    'template'=>'{email}{down}{delete}',

    'buttons'=>array

    (

        'email' => array

        (

            'label'=>'Send an e-mail to this user',

            'imageUrl'=>Yii::app()->request->baseUrl.'/images/email.png',

            'url'=>'Yii::app()->createUrl("users/email", array("id"=>$data->id))',

        ),

        'down' => array

        (


            'label'=>'[-]',

            'url'=>'"#"',

            'visible'=>'$data->score > 0',

            'click'=>'function(){alert("Going down!");}',

        ),

    ),

),




文档上有说明,如果是表达式,要加引号!